Arduino Projects    |   Raspberry Pi  |     Electronic Circuits    |    AVR    |    PIC    |    8051    |    Electronic Projects   |   Free TI Design & Simulation Tools 

Read two matrices, add them, and print all three matrices

Code: 
/*QN 28
 PROGRAM TO READ TWO MATRICES ADD THEM AND PRINT ALL THE THREE MATRICES */ 
#include<stdio.h>
#include<conio.h>
main()
{                
/*declaration of three array with same size */
  int a[10][10],b[10][10],c[10][10],i,j,m,n;
printf("Enter the size of A and B metrix\n");
scanf("%d%d",&m,&n);
     /* reading system */
printf("Enter the elements of A metrix\n");
for(i=0;i<m;i++)
  for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("Enter the elements of B metrix\n");
for(i=0;i<m;i++)
  for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
                /* Addition Logic */
for(i=0;i<m;i++)
  for(j=0;j<n;j++)
  c[i][j] = a[i][j]+b[i][j];
clrscr();
           /*display entire matrix */
printf("\nA matrix is :\n\n");
for(i=0;i<m;i++)
{
   for(j=0;j<n;j++)
printf("%4d", a[i][j]);
   printf("\n");
}
printf("\nB matrix is :\n\n");
 
for(i=0;i<m;i++)
{
   for(j=0;j<n;j++)
printf("%4d", b[i][j]);
   printf("\n");
}
 
printf("\nC matrix is :\n\n");
for(i=0;i<m;i++)
{
     for(j=0;j<n;j++)
printf("%4d", c[i][j]);
printf("\n");
}
 
getch();
}
You are here