C Program for Addtion of 2*2 Diagnol Matrix

C Program for Addtion of 2*2 Diagnol Matrix

View Answers

December 17, 2009 at 12:04 PM

Hi Friend,

Try the following code:

#include <stdio.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("\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("\nEnter the Second matrix:\n");
for(i=0;i<2;i++){
for(j=0;j<2;j++){

scanf("%d",&b[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();
}

Thanks









Related Tutorials/Questions & Answers:

Ads