Addition of matrix

C program to add two matrix :

code

#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][2],b[2][2],c[2][2];
int i,j;
clrscr();
printf(“Enter first matrix :”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf(“\nEnter %d row & %d colum :”,i,j);
scanf(“%d”,&a[i][j]);
}
}
printf(“\nEnter second matrix :”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf(“\nEnter %d row & %d colum :”,i,j);
scanf(“%d”,&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(“Addition of given matrix :\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf(“%d\t”,c[i][j]);

}
printf(“\n”);
}
getch();
}

 


output

Enter first matrix :

Enter 0 row & 0 column :2

Enter 0 row & 1 column :3

Enter 1 row & 0 column :4

Enter 1 row & 1 column :1

Enter second matrix :

Enter 0 row & 0 column :5

Enter 0 row & 1 column :6

Enter 1  row & 0  column :2

Enter 1  row & 1 column :1

Addition of given matrix :

7          9

6           2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s