Advertisement
piffy

Documentazione Esercizio

Sep 6th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. int** comb(int** a , int row , int col)
  5. {
  6.    int mid = col/2;
  7.          for( int i = 0 ; i < row ; i++)
  8.          for( int j = 0 ; j < col ; j++)
  9.                 a[i][j] = 0;
  10.                 a[0][mid] = 1;
  11.      for( int i = 1 ; i < row ; i++)
  12.         {
  13.           for( int j = 1 ; j < col - 1 ; j++)
  14.                a[i][j] = a[i-1][j-1] + a[i-1][j+1];
  15.         }
  16.    return a;
  17. }
  18. void d(int** ptr, int row, int col)
  19. {
  20.   cout << endl << endl;
  21.     for ( int i = 0 ; i < row ; i++)
  22.         {
  23.         for ( int j = 0 ; j < col ; j++)
  24.             {
  25.                 if( ptr[i][j] == 0)
  26.                 cout << "   ";
  27.                 else
  28.                 cout << setw(4) << right << ptr[i][j];
  29.             }
  30.             cout << endl;
  31.         }
  32.     cout << endl << endl;
  33. }
  34. int main()
  35. {
  36.     int **ptr, m, n;
  37.     cout << "\nNumero di righe";
  38.     cin >> m;
  39.     n = 2 * m + 1;
  40.  
  41.     ptr = new int*[m];
  42.     for( int i = 0 ; i < m ; i++)
  43.         ptr[i] = new int[n];
  44.  
  45.         ptr = comb(ptr, m, n);
  46.  
  47.         d(ptr, m, n);
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement