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/E1-2.c
2016-03-16 09:51:20 +01:00

30 lines
579 B
C

/* Triangle de Floyd */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[]) {
int n, i, j, t = 1, S, Sa;
printf("Saisissez n : ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
S = 0;
for (j = 1; j <= i; j++) {
printf("%11d ", t);
S += t;
t++;
}
printf("\n");
Sa = i*(pow(i, 2) + 1)/2;
if (S != Sa) {
printf("Somme incorrecte, %d attendu, %d obtenu.\n", Sa, S);
exit(EXIT_FAILURE);
}
}
return 0;
}