55 lines
757 B
Plaintext
55 lines
757 B
Plaintext
----- TP27 : Récursivité -----
|
|
|
|
1.
|
|
|
|
|
|
|
|
2.
|
|
|
|
# include <stdio.h>
|
|
# include <stdlib.h>
|
|
|
|
|
|
int fibonacci(int n) {
|
|
if (n == 0) {
|
|
return 0;
|
|
}
|
|
if (n == 1) {
|
|
return 1;
|
|
}
|
|
return (fibonacci(n-2) + fibonacci(n-1));
|
|
}
|
|
|
|
void affiche_fibonacci(int m) {
|
|
int i;
|
|
for (i = 0; i != m; i++) {
|
|
printf("%d\n", fibonacci(i));
|
|
}
|
|
}
|
|
|
|
|
|
int main(void) {
|
|
/*printf("%d",fibonacci(7));*/
|
|
affiche_fibonacci(15);
|
|
}
|
|
|
|
3.
|
|
|
|
# include <stdio.h>
|
|
# include <stdlib.h>
|
|
|
|
void affiche_tableau(double* t, int len) {
|
|
if (sizeof(double)*len == sizeof(double)) {
|
|
printf("%.2f\n", t[len-1]);
|
|
}
|
|
else {
|
|
printf("%.2lf, ", t[0]);
|
|
affiche_tableau(&t[1], len-1);
|
|
}
|
|
}
|
|
|
|
int main(void) {
|
|
double t[5] = {1.25, 47.80, 77.01, 54.23, 895.14};
|
|
affiche_tableau(t, 5);
|
|
return EXIT_SUCCESS;
|
|
} |