Friday, 22 June 2012

write a c program to calculate sum of m*n matrix


/*write a c program to calculate sum of m*n matrix */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],add[10][10];
int r1,c1,r2,c2,i,j;
clrscr();
printf("\nenter the rows & coloumn matrix a");
scanf("%d%d",&r1,&c1);
printf("\nenter the rows & coloumn of matrix");
scanf("%d%d",&r2,&c2);
if((r1==r2)&&(c1==c2))
{
r1=r2;
c1=c2;
printf("\nthe matrix can be added :");
printf("\nthe rows & coloumn of resultant matrix is :%d,%d",r2,c2 );
printf("enter the element of matrix a:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the element of matrix b :\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("the display of matrix a :\n");
for(i=0;i<r2;i++)
{

for(j=0;j<c2;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("the display of matrix b :\n");
for(i=0;i<r2;i++)
{

for(j=0;j<c2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
add[i][j]=a[i][j]+b[i][j];
}
}
printf("\nthe addition of matrix is :\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%d\t",add[i][j]);
}
printf("\n");
}
}
else

printf("invalid input");
getch();
}
/*
enter the rows & coloumn matrix a3 3                                          
                                                                               
enter the rows & coloumn of matrix3 3                                          
                                                                               
the matrix can be added :                                                      
the rows & coloumn of resultant matrix is :3,3enter the element of matrix a:  
1 2 3                                                                          
4 5 6                                                                          
7 8 9                                                                          
enter the element of matrix b :                                                
1 4 5
3 6 2                                                                          
1 4 7                                                                          
the display of matrix a :                                                      
1       2       3                                                              
4       5       6                                                              
7       8       9                                                              
the display of matrix b :                                                      
1       4       5
3       6       2
1       4       7

the addition of matrix is :
2       6       8
7       11      8
8       12      16
*/

No comments: