Thursday, September 20, 2012

program for matrix addition(exact look)

c program code for finding  the sum of 2 matrics in exact look......
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20][20],b[20][20],c[20][20],i,j,m,n;
clrscr();
printf("enter the rows and columns of the first matrics\n");
scanf("%d%d",&m,&n);
printf("Enter the first matrics\n");
for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
      {
      scanf("%d",&a[i][j]);
      }
 }
printf("Enter the second matrics\n");
for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
      {
      scanf("%d",&b[i][j]);
      }
  }
 printf("The matrics sum\n");
for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
      {
      printf("%d    ",a[i][j]);
      }
      if(i==n/2 )
      {
      printf("  +  ");
      }
      else
      {
      printf("     ");
      }
      for(j=0;j<n;j++)
      {
      printf("%d     ",b[i][j]);
      }
      if(i==n/2)
      {
      printf("  =  ");
      }
      else
      {
      printf("     ");
      }
      for(j=0;j<n;j++)
      {
      c[i][j] = a[i][j]+b[i][j];
      printf("%d    ",c[i][j]);
      }
      printf("\n");
  }
  getch();
  }

No comments:

Post a Comment