Write a ‘C’ program to calculate the sum of two mXn matrix and store the result in third matrix

#include<stdio.h>
#include<conio.h>

void main()
{
int i,j,a[3][3],b[3][3],c[3][3];
clrscr();
printf("programme for matrix addition");
printf("\n\nEnter the number for a:");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("you entered\n\n:");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\t%d",a[i][j]);
}
printf("\n");
}
printf("\n\nEnter the number for b:");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
scanf("%d",&b[i][j]);
}
printf("\n");
}
printf("\n\nyou entered:\n\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\t%d",b[i][j]);
}
printf("\n");
}
printf("Addition of matrix is:");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
printf("\n");
}
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
getch();
}

Comments

  1. Thanks .. nice program for beginners. As per my understanding the time complexity of adding two matrix in C is O(n^2).

    ReplyDelete

Post a Comment