Developpement/23DEV1.1/TPS1/TP2/22-Recursive/Fibonacci.c

51 lines
674 B
C
Raw Permalink Normal View History

2024-12-09 11:53:11 +01:00
#include <stdio.h>
#include <stdlib.h>
int Fibonacci(int n)
{
if(n==0)
{
return 0;
}
if(n==1)
{
return 1;
}
if(n>=2)
{
n = Fibonacci(n-2)+Fibonacci(n-1);
return n;
}
Fibonacci(n+1);
}
int afficheFibo(int m)
{
if(m!=0)
{
if(m==1)
{
printf("u%d = %d",m,Fibonacci(1));
}
if(m>=2)
{
printf("u%d = %d",m,Fibonacci(m));
}
afficheFibo(m-1);
}
if(m==0)
{
printf("u%d = %d\n",m,Fibonacci(0));
return 0;
}
}
int main(int argc, char const *argv[])
{
int m = 15;
afficheFibo(m);
//int n;
//printf("choisissez un nombre : ");
//scanf("%d",&n);
//printf("u%d = %d",n,Fibonacci(n));
return 0;
}