Advertisement
Mouamle

deepSum.cpp

May 17th, 2018
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int deepSumCol(int data[3][3], int n, int m){
  6.     if (n == 1)
  7.         return data[m][0];
  8.     else
  9.         return deepSumCol(data, n-1, m) + data[m][n - 1];
  10. }
  11.  
  12. int deepSum(int data[3][3], int n, int m){
  13.     if(n == 1)
  14.         return deepSumCol(data, m, 0);
  15.     else
  16.         return deepSum(data, n -1, m) + deepSumCol(data, m, n - 1);
  17. }
  18.  
  19. int main(){
  20.     int a[3][3] = {
  21.         {1, 2, 3},
  22.         {1, 2, 3},
  23.         {1, 2, 3}
  24.     };
  25.    
  26.     cout << deepSum(a, 3, 3) << endl;
  27.    
  28.    
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement