Write a program to find sum matrix of two matrix

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 :)



  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a[10][10],b[10][10],c[10][10],m,n,i,j;
  7. cout<<"Enter number of rows: ";
  8. cin>>m;
  9. cout<<"Enter number of coloumns: ";
  10. cin>>n;
  11. cout<<endl<<"Enter elements of matrix A: "<<endl;
  12. for(i=0;i<m;i++)
  13. {
  14. for(j=0;j<n;j++)
  15. {
  16. cout<<"Enter element a"<<i+1<<j+1<<": ";
  17. cin>>a[i][j];
  18. }
  19. }
  20. cout<<endl<<"Enter elements of matrix B: "<<endl;
  21. //Coding by: Snehil Khanor
  22. //http://WapCPP.blogspot.com
  23. for(i=0;i<m;i++)
  24. {
  25. for(j=0;j<n;j++)
  26. {
  27. cout<<"Enter element b"<<i+1<<j+1<<": ";
  28. cin>>b[i][j];
  29. }
  30. }

  31. cout<<endl<<"Displaying Matrix A: "<<endl<<endl;
  32. for(i=0;i<m;i++)
  33. {
  34. for(j=0;j<n;j++)
  35. {
  36. cout<<a[i][j]<<" ";
  37. }
  38. cout<<endl<<endl;
  39. }
  40. cout<<endl<<"Displaying Matrix B: "<<endl<<endl;
  41. for(i=0;i<m;i++)
  42. {
  43. for(j=0;j<n;j++)
  44. {
  45. cout<<b[i][j]<<" ";
  46. }
  47. cout<<endl<<endl;
  48. }
  49. cout<<endl<<"Matrix A + Matrix B = Matrix C: "<<endl<<endl;
  50. for(i=0;i<m;i++)
  51. {
  52. for(j=0;j<n;j++)
  53. {
  54. cout<<a[i][j]+b[i][j]<<" ";
  55. }
  56. cout<<endl<<endl;
  57. }

  58. getch();
  59. }

Check out this stream