Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, February 16, 2011

C20 : Matrix addition

Back to Home   &  C


//Program to enter a matrix and print its addition

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[5][5],b[5][5],c[5][5],i,j,r,cl;
printf("Enter row and column\n");
scanf("%d%d",&r,&cl);
printf("Enter elements of first matrix\n");
for(i=0;i<r;i++)
{
for(j=0;i<cl;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Matrix elements of second matrix");
for(i=0;i<r;i++)
{
for(j=0;i<cl;j++)
{
 scanf("%d",&b[i][j]);
}
}
for(i=0;i<r;i++)
{
for(j=0;i<cl;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<r;i++)
{
for(j=0;i<cl;j++)
{
printf("%d\t",c[i][j]);
printf("\n");
}
getch();
}
}
-------------------------------------------------------------------
Output
Enter row and column
2
2
Enter elements of first matrix
1
1
1
1
Enter elements of second matrix
2
2
2
2
----------------
3   3
3   3
(May be some error in output)
================================
Back to Home   &  C