karbaev

matrix-sum

Mar 8th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. main()
  6. {
  7.    int m, n, c, d, first[10][10], second[10][10], sum[10][10];
  8.  
  9.    cout << "Enter the number of rows and columns of matrix ";
  10.    cin >> m >> n;
  11.    cout << "Enter the elements of first matrix\n";
  12.  
  13.    for (  c = 0 ; c < m ; c++ )
  14.       for ( d = 0 ; d < n ; d++ )
  15.          cin >> first[c][d];
  16.  
  17.    cout << "Enter the elements of second matrix\n";
  18.  
  19.    for ( c = 0 ; c < m ;c++ )
  20.       for ( d = 0 ; d < n ; d++ )
  21.             cin >> second[c][d];
  22.  
  23.    for ( c = 0 ; c < m ; c++ )
  24.       for ( d = 0 ; d < n ; d++ )
  25.          sum[c][d] = first[c][d] + second[c][d];
  26.  
  27.    cout << "Sum of entered matrices:-\n";
  28.  
  29.    for ( c = 0 ; c < m ; c++ )
  30.    {
  31.       for ( d = 0 ; d < n ; d++ )
  32.          cout << sum[c][d] << "\t";
  33.  
  34.       cout << endl;
  35.    }
  36.  
  37.    return 0;
  38. }
Add Comment
Please, Sign In to add comment