Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Matrix(3*3) Addition in C-Language



In this C program we will add two matrices(3*3) and print the result on the screen.The elements of the matrices will be taken from the user.color>

input:

The elements of matrices(3*3).

output:

The Sum of the two matrices.

CODE---->



#include
int main()
{
int mat1[10][10],mat2[10][10],mat3[20][20],i,j;
printf("Please,Enter the first matrix--->> ");
for(i=1;i3;i++)
{
for(j=1;j3;j++)
{
printf("\nPlease,Enter data: ");
scanf("%d",&mat1[i][j]);
}
}
printf("\n\nPlease,Enter the second matrix--->> ");
for(i=1;i3;i++)
{
for(j=1;j3;j++)
{
printf("\nPlease,Enter data: ");
scanf("%d",&mat2[i][j]);
}
}
printf("\n\nThe sum of the matrices --->> \n");
for(i=1;i3;i++)
{
for(j=1;j3;j++)
{
mat3[i][j]=mat1[i][j]+mat2[i][j];
}
}
for(i=1;i3;i++)
{
for(j=1;j3;j++)
{
printf(" %d ",mat1[i][j]);
}
printf("\n");
}
printf(" +\n");
for(i=1;i3;i++)
{
for(j=1;j3;j++)
{
printf(" %d ",mat2[i][j]);
}
printf("\n");
}
printf(" ||\n");
for(i=1;i3;i++)
{
for(j=1;j3;j++)
{
printf(" %d ",mat3[i][j]);
}
printf("\n");
}
return 0;
}


Download the C-Program file of this Program.

Don't just read, run on your pc !!!color>


RESULT :color>



Please,Enter the first matrix--->>
Please,Enter data: 11

Please,Enter data: 22

Please,Enter data: 33

Please,Enter data: 44

Please,Enter data: 55

Please,Enter data: 66

Please,Enter data: 77

Please,Enter data: 88

Please,Enter data: 99


Please,Enter the second matrix--->>
Please,Enter data: 9

Please,Enter data: 8

Please,Enter data: 7

Please,Enter data: 6

Please,Enter data: 5

Please,Enter data: 4

Please,Enter data: 3

Please,Enter data: 2

Please,Enter data: 1


The sum of the matrices --->>
11 22 33
44 55 66
77 88 99
+
9 8 7
6 5 4
3 2 1
||
20 30 40
50 60 70
80 90 100

--------------------------------
Process exited after 24.41 seconds with return value 0
Press any key to continue . . .


Images for better understanding : color>




This post first appeared on ProgramJoy.blogspot.com, please read the originial post: here

Share the post

Matrix(3*3) Addition in C-Language

×

Subscribe to Programjoy.blogspot.com

Get updates delivered right to your inbox!

Thank you for your subscription

×