Sunday, October 21, 2007

programe for multiplication of 2 matrix of any size

/*prg to for multiflication of matrixes
written by sekhar
written on 16/07/07
modified on 18/07/07 */
#include
main()
{
int s,i,j,k,l,m,n,o,x,y,a[6][6],b[6][6],c[6][6],d[6];
printf("enter the order of matrix");
scanf("%d",&s);
printf("enter the elements of first matrix\n");
for(i=0;i{
for(j=0;j{
printf("\nenter(%d,%d)element:",i,j);
scanf("%d",&a[i][j]);
}
printf("\n");
} //scan of first matrix
printf("enter the elements of second matrix\n");
for(k=0;k{
for(l=0;l{
printf("\nenter(%d,%d)element:",k,l);
scanf("%d",&b[k][l]);
}
printf("\n");
} //scan of second matrix
for(m=0;m{
for(n=0;n{
y=0;
for(o=0;od[o]=a[m][o]*b[o][n];
for(x=0;xy=y+d[x];
c[m][n]=y;
printf("\t%d",c[m][n]);
}
printf("\n");
}
}

programe to display elements in matrix formate what we have entered

/* pgr on array to display matrix
written by sekhar
written on 16/07/07
modified on 16/07/07 */
#include
main()
{
int matrix[3][3],i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\t(%d,%d)\t",i,j);
scanf("%d",&matrix[i][j]);
printf("%u",&matrix[i][j]);
}
printf("\n");
}
printf("you have entered values\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
// printf("\t(%d,%d)\t",i,j);
printf("\t%d",matrix[i][j]);
// printf("%u",&matrix[i][j]);
}
printf("\n");
}
printf("%d",sizeof(matrix));
}

multiplication of 2 matrix

/*pgr for multiplication of charecter array
written by sekhar
written on 17/07/07
modified on 17/07/07 */
#include
main()
{
int i,j,k,l,m,n,o;
char a[3][3],b[3][3],c[3][3],d[3];
printf("enter the elements of first matrix\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\nenter(%d,%d)element:",i,j);
scanf("%c",&a[i][j]);
}
printf("\n");
} //scan of first matrix
printf("enter the elements of second matrix\n");
for(k=1;k<=3;k++)
{
for(l=1;l<=3;l++)
{
printf("\nenter(%d,%d)element:",k,l);
scanf("%c",&b[k][l]);
}
printf("\n");
} //scan of second matrix
for(m=1;m<=3;m++)
{
for(n=1;n<=3;n++)
{
for(o=1;o<=3;o++)
d[o]=a[m][o]*b[o][n];
c[m][n]=d[1]+d[2]+d[3];
printf("\t%c",c[m][n]);
}
printf("\n");
}
}

finding largest number in 2 dim array

/*pgr to find largest number in 2 dimensional array
written by sekhar
written on 20/07/07
modified on 20/07/07 */
#include
main()
{
int a[3][3],i,j,t;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(a[0][0]<=a[i][j])
{
t=a[0][0];
a[0][0]=a[i][j];
a[i][j]=t;
}
// printf("\n%d",a[0][0]);
}
}
printf("greatest\n%d",a[0][0]);
}

string operations like string copy , string concat,str word count,string length,string compare

/* pgr to find string operations in infinite loop
written by sekhar
written on 30/07/07*/
#include
void string_copy(char *,char *);
void string_concat(char *,char *);
void string_word_count(char *,int *);
int string_length(char *);
int string_cmp(char *,char *);
main()
{
int option,count=0,x,y;
char str1[40],str2[40],strs1[40],strs2[40];
puts("enter the string:");
gets(str1);
while(1)
{
printf("1:for string copy, 2;string concatenate3:count string word count,4:strig length");
scanf("%d",&option);
switch(option)
{
case 1:
string_copy(str1,str2);
puts(str2);
break;
case 2:
string_concat(str1,str2);
puts(str1);
break;
case 3:
string_word_count(str1,&count);
printf("%d",count);
break;
case 4:
x=string_length(str1);
printf("%d",x);
break;
case 5:
puts("enter first string for compare:");
gets(strs1);
puts("enter second string for compare:");
gets(strs2);
y=string_cmp(strs1,strs2);
printf("%d",y);
break;
/* case 6:
string_char_str();
break;*/
case 7:
exit();
}
}
}
void string_copy(char *s1,char *s2)
{
while(*s1!='\0')
*s2++=*s1++;
*s2='\0';
}
void string_concat(char *s1,char *s2)
{
while(*++s1!='\0')
*s1=*s1;
puts(s2);
while(*s2!='\0')
{
puts(s2);
*s1++=*s2++;
}
*s1='\0';
}
//function for word length
void string_word_count(char *s1, int *cou)
{
while(*s1++!='\0')
{
if(*s1==32*s1=='\0') // 32 in ascii equelent of ' '
{
*cou=*cou+1;
}
}
}
//function for calculate string length
int string_length(char *s1)
{
int cou=0;
while(*s1++!='\0')
{
cou++;
}
return cou;
}
//function for compare two strings
int string_cmp(char *s1,char *s2)
{
int co=0;
while(*s1++!='\0'&&*s2++!='\0')
{
co=*s1-*s2;
}
return co;
}