Two matrix are taken from user.. Sum matrix is displayed as output..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
- #include<iostream.h>
- #include<conio.h>
- void main()
- {
- clrscr();
- int a[10][10],b[10][10],c[10][10],m,n,i,j;
- cout<<"Enter number of rows: ";
- cin>>m;
- cout<<"Enter number of coloumns: ";
- cin>>n;
- cout<<endl<<"Enter elements of matrix A: "<<endl;
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- cout<<"Enter element a"<<i+1<<j+1<<": ";
- cin>>a[i][j];
- }
- }
- cout<<endl<<"Enter elements of matrix B: "<<endl;
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- cout<<"Enter element b"<<i+1<<j+1<<": ";
- cin>>b[i][j];
- }
- }
- cout<<endl<<"Displaying Matrix A: "<<endl<<endl;
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- cout<<a[i][j]<<" ";
- }
- cout<<endl<<endl;
- }
- cout<<endl<<"Displaying Matrix B: "<<endl<<endl;
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- cout<<b[i][j]<<" ";
- }
- cout<<endl<<endl;
- }
- cout<<endl<<"Matrix A + Matrix B = Matrix C: "<<endl<<endl;
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- cout<<a[i][j]+b[i][j]<<" ";
- }
- cout<<endl<<endl;
- }
- getch();
- }
1 comments:
U assigned a 2-D array c[10][10] in the beginning which is never used in the program.. why?
Post a Comment