Write a C program for matrix addition with the help of function add(int a[ ][20], int b[ ][20], int n, int m) where a and b are matrix to be added and n and m are dimension of a and b.

#include<stdio.h>
void add(int a[][20], int b[][20], int c[][20], int m, int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
}
void main()
{
int a[20][20],b[20][20],c[20][20];
int i,j,m,n;
printf("enter row and coumn of matrices:");
scanf("%d%d",&m,&n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\na[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\nb[%d][%d]=",i,j);
scanf("%d",&b[i][j]);
}
}
add (a,b,c,m,n);
printf("the matrix after addition is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",c[i][j]);
}
if(j=m-1)
{
printf("\n\n");
}
}
}






credit: Unknown

Comments

Popular posts from this blog