Monday, 7 November 2011

C program to add two matrix

WRITE A C PROGRAM TO ADD TWO MATRICES OF ORDER M*N





#include<stdio.h>
#include<conio.h>
void main()
{
 int m,n,i,j,a[10][10],b[10][10],c[10][10];
 printf("Enter the number of row:");
 scanf("%d",&m);
 printf("Enter the number of column:");
 scanf("%d",&n);
 printf("Enter the first matrix:\n");
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
  {
    scanf("%d",&a[i][j]);
  }
   printf("\n"); 
 }
 printf("\nEnter the second matrix:");
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
  {
   scanf("%d",b[i][j]);
  }
  printf("\n");
 }
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
  {
   c[i][j]=a[i][j]+b[i][j];
  }
 }
 printf("The resultant matrix is:\n"):
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
  {
   printf("%d ",c[i][j]);
   }
  printf("\n");
 }
 getch();
}


Output:
Enter the number of row: 2
Enter the number of column: 2
Enter the first matrix:
1 1
1 1
Enter the second matrix:
1 1
1 1
The resultant matrix is:
2 2
2 2

1 comment:

  1. Iron Set Off Metal detectors in Georgia
    Iron Set On Metal titanium trim reviews detectors · IGA-19B oakley titanium sunglasses is a contractor that produces the Iron Set off-Metal detectors located toaks titanium in Georgia. · A.L.A. titanium block has columbia titanium boots its own Iron Set

    ReplyDelete