Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Square Matrix Addition and Subtraction ......

  Program for the Addition & Subtraction of two square Matrix (using two dimensional array).
well simple program, user can input the value of row & column,since it is a square matrix
so row & column of both matrix is same.

 


Source Code:-

#include<iostream.h>
#include<conio.h>
void main()
 { clrscr();
   int i,j,r,c,choice;
   int matrix1[5][5];
   int matrix2[5][5];
   int sum[5][5],sub[5][5];
   cout<<"Square Matrix Addition & Subtraction by-Tarun Rawat\n";
   cout<<"Enter Row & Column  = ";cin>>r>>c;
   cout<<"Enter matrix 1st \n";
   for (i=0;i<r;i++)
       {for (j=0;j<c;j++)
   {cin>>matrix1[i][j];
   }
       }
    cout<<"Entered Matrix is\n";
    for (i=0;i<r;i++)
{for (j=0;j<c;j++)
   {cout<<matrix1[i][j]<<" ";
   }cout<<"\n";
}
   cout<<"\nEnter matrix 2nd \n";
   for (i=0;i<r;i++)
       { for (j=0;j<c;j++)
    {cin>>matrix2[i][j];
    }
       }
   cout<<"Entered matrix is\n";
   for (i=0;i<r;i++)
       { for (j=0;j<c;j++)
    {cout<<matrix2[i][j]<<" ";
    }cout<<"\n";
       }
   cout<<"\nEnter Choice: 1 = Addition 2 = Subtraction\n";
   cin>>choice;
   if(choice==1)
     {  cout<<"Addition of matrix \n";
for (i=0;i<r;i++)
 { for (j=0;j<c;j++)
    { sum[i][j]=matrix1[i][j]+matrix2[i][j];
    cout<<sum[i][j]<<" ";
    }cout<<"\n";
 }
     }
   if(choice==2)
    {  cout<<"Subtraction of matrix \n";
       for (i=0;i<r;i++)
 { for (j=0;j<c;j++)
    { sub[i][j]=matrix1[i][j]-matrix2[i][j];
    cout<<sub[i][j]<<" ";
    }cout<<"\n";
 }
     }
getch();

}





No comments:

Post a Comment

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)