Friday, 7 December 2012

Addition of Matrices in C++


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int m1[20][20],m2[20][20],i,j,r,c,h,v;
cout<<"\t\t\t\tEnter matrix order";
cout<<"\n\n\n\tEnter number of rows="; cin>>r;
cout<<"\n\tEnter number of columns="; cin>>c;
cout<<"\n\tEnter 1st matrix=";
gotoxy(10,5);
 v=10;
for(i=0;i<r;i++)
 {
h=10;
  for(j=0;j<c;j++)
    {
     gotoxy(h,v);
     cin>>m1[i][j];
      h+=3;
    }
v+=2;
 }

gotoxy(50,8);
cout<<"enter 2nd matrix=";
v=10; h=50;
 for(i=0;i<r;i++)
 {
 h=50;
  for(j=0;j<c;j++)
  {
      gotoxy(h,v);
      cin>>m2[i][j];
      h+=3;
 }
v+=2;
}
gotoxy(30,30);
cout<<"sum of matrices=";
v=32;  h=30;
  for(i=0;i<r;i++)
  {
  h=30;
    for(j=0;j<c;j++)
    {
       gotoxy(h,v);
       cout<<m1[i][j]+m2[i][j];
       h+=3;
  }
v+=2;
}
getch();
}

1 comment:

  1. this is really good for students.... thanks man

    ReplyDelete