Wednesday, February 13, 2013

Program to perform addition of two 2 by 2 matrix

#include<stdio.h>
#include<conio.h>
void main(){
int arr1[10][10], arr2[10][10];
int arr3[][3]={
{0,0,0},
{0,0,0},
{0,0,0}
};
int i, j;
clrscr();
printf("Enter 3x3 array 1:\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("Enter element %d x %d:",i,j);
scanf("%d",&arr1[i][j]);
}
}
printf("Enter 3x3 array 2:\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("Enter element %d x %d:",i,j);
scanf("%d",&arr2[i][j]);
}
}

for(i=0;i<3;i++){
for(j=0;j<3;j++){
arr3[i][j]=arr1[i][j] + arr2[i][j];
}
}

printf("Addition of Array 1 and Array 2 is: \n");
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("\t%d",arr3[i][j]);
}
printf("\n");
}
getch();
}

Output:
Enter 3x3 array 1:
Enter element 0 x 0:1
Enter element 0 x 1:1
Enter element 0 x 2:1
Enter element 1 x 0:1
Enter element 1 x 1:1
Enter element 1 x 2:1
Enter element 2 x 0:1
Enter element 2 x 1:1
Enter element 2 x 2:1
Enter 3x3 array 2:
Enter element 0 x 0:1
Enter element 0 x 1:1
Enter element 0 x 2:1
Enter element 1 x 0:1
Enter element 1 x 1:1
Enter element 1 x 2:1
Enter element 2 x 0:1
Enter element 2 x 1:1
Enter element 2 x 2:1
Addition of Array 1 and Array 2 is:
2 2 2
2 2 2
2 2 2


Follow us on Facebook

No comments:

Post a Comment