summaryrefslogtreecommitdiff
path: root/sem_2/HLIN202/TP/TP3-4/bonus/bonus.cpp
blob: 8a8b6a3e66e4c6e1b8604cd4fa88827ba5a95952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
#include<math.h>

void triangle (int k);
int combo ( int, int);

int main () {
  triangle ( 20 );
  return 0;

}

void triangle ( int k ) {
  int n,p,ligne;
  n = 0;
  p = 0;
  ligne = 1;
  while ( p <= k) {
  while ( n <=p ) {
    for ( int i=0; i < ligne; i ++) {
      std::cout<< combo ( n, i ) << "   ";
    }
    std::cout<<std::endl;
    n ++;
    ligne ++;
  }
  p ++;
}
}

int combo ( int n, int p) {
  return (n == p || p == 0) ? 1 : combo(n-1,p) + combo ( n-1,p-1);
}