Advertisement
ElooEminem

Untitled

Apr 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4.  
  5. #define N 8
  6.  
  7. int trojkat( int** tab , int x , int y ){ //x - nr kolumny , y - numer wiersza
  8. if( x==0 || x==y ) return tab[y][x]=1;
  9. else return tab[y][x]=trojkat( tab , x-1 , y-1 ) + trojkat( tab , x , y-1 );
  10. }
  11.  
  12. int main(){
  13. int** tab=new int* [N];
  14. for( int i=0 ; i<N ; i++ ) tab[i]=new int [i+1];
  15.  
  16. tab[0][0]=1; //Przez ten punkt rekurencja nie przejdzie, bo linijke nizej obydwa
  17. //elementy to warunki brzegowe, a rekurencja idzie w gore
  18.  
  19. for( int i=0 ; i<N ; i++ ) tab[N-1][i]=trojkat ( tab , i , N-1 ); //Ta rekuencja idze w gore, wiec trzeba ja
  20. //odpalic dla wszystkich dolnych elementow
  21. for( int i=0 ; i<N ; i++ ){
  22. cout<<endl;
  23. for( int j=0; j<i+1 ; j++ ) cout<<tab[i][j]<<" ";
  24. }
  25. getche();
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement