Let Us C (Chapter 8 : Arrays) : Program-13_1
(1) Write a program to add two 6 x 6 matrices.
// Let Us C (Chapter 8 : Arrays) : Program-13_1
/* (1) Write a program to add two 6 x 6 matrices. */
#include<stdio.h>
#include<conio.h>
void main()
{
int M1[6][6], M2[6][6], M3[6][6],i,j,k=1;
clrscr();
printf("\nProgram for Addition of Matrices");
printf("\nEnter two 6 X 6 matrices");
printf("\nEnter 36 elements of 1st Matrix separated by space\n");
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
scanf("%d",&M1[i][j]);
}
}
printf("\nEnter 36 elements of 2nd Matrix seprated by space\n");
k=1;
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
//printf(" Enter Element %d : ",k++);
scanf("%d",&M2[i][j]);
}
}
printf("***** 1st Matrix *****\n");
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
printf("%4d",M1[i][j]);
}
printf("\n");
}
printf("***** 2nd Matrix *****\n");
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
printf("%4d",M2[i][j]);
}
printf("\n");
}
printf("\n******* Addition of Matrices ********\n");
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
M3[i][j] = M1[i][j] + M2[i][j];
printf("%4d",M3[i][j]);
}
printf("\n");
}
}
OUTPUT
Comments
Post a Comment