This repository has been archived on 2019-08-09. You can view files and clone it, but cannot push or open issues or pull requests.
s4-c/DS1-2015/E2.c
2016-02-24 11:05:25 +01:00

41 lines
772 B
C

/* Triangle de Pascal */
#include <stdio.h>
int main() {
int N;
int x, y;
printf("Saisir N : ");
scanf("%d", &N);
// On crée un tableau, et on le remplit de 0
int T[N+1][N+1];
for (y = 0; y <= N; y++) {
for (x = 1; x < N; x++) {
T[x][y] = 0;
}
T[0][y] = 1; // On met des 1 sur la première colonne
}
// On calcule les sommes
for (y = 0; y <= N; y++) {
for (x = 1; x <= y; x++) {
T[x][y] = T[x-1][y-1] + T[x][y-1];
}
}
// On affiche le tableau
for (y = 0; y <= N; y++) {
for (x = 0; x < N; x++) {
if (x <= y) {
printf("%11d", T[x][y]);
}
}
printf("\n");
}
return 0;
}