Custom Search

Monday 28 November 2011

Q6)Write a program to add 2 matrices?


Author: Sanif S S 
Site: theeduzone.blogspot.com 
Email: sanifss@gmail.com

#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 int m1[20][20],m2[20][20],s[20][20],i,j,m,n,p,q;
 printf("\nenter the order of the first matrix : ");
 scanf("%d %d",&m,&n);
 printf("\nenter the order of the second matrix : ");
 scanf("%d %d",&p,&q);
 if((m==p)&&(n==q))
 {
  printf("\n\nenter the elements of first matrix : ");
  for(i=0;i  for(j=0;j  scanf("%d",&m1[i][j]);
  printf("\nenter the elements of second matrix : ");
  for(i=0;i

  for(j=0;j  scanf("%d",&m2[i][j]);
  printf("\n\nfirst matrix : \n");
  for(i=0;i  {
   for(j=0;j   printf(" %d ",m1[i][j]);
   printf("\n");
  }
  printf("\nsecond matrix : \n");
  for(i=0;i
  {
   for(j=0;j   printf(" %d ",m2[i][j]);printf("\n");
  }
printf("\nsum of the two matrices :\n");
  for(i=0;i  {
   for(j=0;j   {
    s[i][j]=m1[i][j]+m2[i][j];
    printf(" %d ",s[i][j]);
   }
   printf("\n");
  }
  }
 else
 {
  printf("\n\n\naddition not possible");
  }
 getch();
}

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...