. C program to accept two square
matrix and find sum of two matrices.
#include<stdio.h>
#include<conio.h>
void
main()
{
int a[2][2],b[2][2],c[2][2],i,j;
clrscr();
printf("Enter the First matrix->\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nEnter the Second
matrix->");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\nThe First matrix is\n");
for(i=0;i<2;i++)
{
printf("\n");
for(j=0;j<2;j++)
{
printf("%d\t",a[i][j]);
}
}
printf("\nThe Second matrix is\n");
for(i=0;i<2;i++)
{
printf("\n");
for(j=0;j<2;j++)
{
printf("%d\t",b[i][j]);
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\nThe Addition of two matrix
is\n");
for(i=0;i<2;i++)
{
printf("\n");
{
for(j=0;j<2;j++)
printf("%d\t",c[i][j]);
}
}
getch();
}
INPUT:
Enter the First
matrix->
2
2
3
4
Enter the Second
matrix->
1
2
3
4
OUTPUT:
The First matrix
is
2 2
3 4
The Second matrix
is
1 2
3 4
The Addition of
two matrix is
3 4
6 8
No comments:
Post a Comment