Friday, November 11, 2011

Matrix Addition in C laguage



#include<stdio.h>
int main(){
  int a[3][3],b[3][3],c[3][3],i,j;
  printf("Please Enter values for first Matrix: ");
  for(i=0;i<3;i++)
  {
      for(j=0;j<3;j++)
      {
           scanf("%d",&a[i][j]);
      }
  }
  printf("Please Enter values for second Matrix: ");
  for(i=0;i<3;i++)
  {
      for(j=0;j<3;j++)
      {
           scanf("%d",&b[i][j]);
      }
  }
  // Addition operations
   for(i=0;i<3;i++)
       for(j=0;j<3;j++)
            c[i][j]=a[i][j]+b[i][j];
   printf("\n Result after Addition of two matrix is\n");
   for(i=0;i<3;i++)
   { 
       for(j=0;j<3;j++)
            printf("%d\t",c[i][j]);
       printf("\n");
   }
}

0 comments:

Post a Comment

You are most welcome for making comments here. I will consider your view and will reply you soon.