This Program helps us to add a 3*3 matrix. The concept of 'arrays'is used here. For loops are used to get the inputs and print them. To add matrix of order n*n change all the 3 to n.
PROGRAM:
PROGRAM:
#include <stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3];
int i,j;
clrscr();
printf("\nEnter the first matrix:");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("\nThe first matrix is");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf ("\t%d",a[i][j]);
}
printf ("\nEnter the second matrix is");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("\t%d",&b[i][j]);
printf("\nThe Second Matrix is:");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf ("\t%d",b[i][j]);
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
printf("\nThe Resultant matrix is:");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf ("\t%d",c[i][j]);
}
getch();
}
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3];
int i,j;
clrscr();
printf("\nEnter the first matrix:");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("\nThe first matrix is");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf ("\t%d",a[i][j]);
}
printf ("\nEnter the second matrix is");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("\t%d",&b[i][j]);
printf("\nThe Second Matrix is:");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf ("\t%d",b[i][j]);
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
printf("\nThe Resultant matrix is:");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf ("\t%d",c[i][j]);
}
getch();
}
No comments:
Post a Comment