APL/APL1.1/TP07/progression.c

28 lines
632 B
C
Raw Permalink Normal View History

2021-09-28 15:59:07 +02:00
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char * argv[]) {
int desired_index, value;
printf("Saisissez le numéro de terme souhaité : ");
scanf("%d", &desired_index);
int index_m2 = 0;
int index_m1 = 1;
if (desired_index < 2 && desired_index >= 0 ) value = desired_index;
else if (desired_index > 1) {
for (int index = 2; index <= desired_index; index++) {
value = index_m2 + index_m1;
index_m2 = index_m1;
index_m1 = value;
}
} else {
printf("Valeur invalide.\n");
return EXIT_SUCCESS;
}
printf("Le %dème terme de la suite est : %d\n", desired_index, value);
return EXIT_SUCCESS;
}