From 8699cdede411d17e12f16a982d692f2fdac2eecf Mon Sep 17 00:00:00 2001 From: pourchot Date: Wed, 14 Dec 2022 15:31:36 +0100 Subject: [PATCH] 14 Decembre --- DEV1.1/TP16:Recursivite/fibonacci.c | 24 ++++++++++++++++++++++++ DEV1.1/TP16:Recursivite/phases.c | 17 +++++++++++++++++ DEV1.1/TP16:Recursivite/tableau.c | 20 ++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 DEV1.1/TP16:Recursivite/fibonacci.c create mode 100644 DEV1.1/TP16:Recursivite/phases.c create mode 100644 DEV1.1/TP16:Recursivite/tableau.c diff --git a/DEV1.1/TP16:Recursivite/fibonacci.c b/DEV1.1/TP16:Recursivite/fibonacci.c new file mode 100644 index 0000000..f251395 --- /dev/null +++ b/DEV1.1/TP16:Recursivite/fibonacci.c @@ -0,0 +1,24 @@ +#include +#include + +int fibonacciRec(int n){ + if(n==0){ + return 0; + } if (n==1){ + return 1; + } return (fibonacciRec(n-1)+fibonacciRec(n-2)); +} + +void afficheFiboRec(int m){ + if(m==1){ + printf("Le 1er terme de la suite de fibonacci est: 0\n"); + }else{ + afficheFiboRec(m-1); + printf("Le %dieme terme de la suite de fibonacci est: %d\n",m,fibonacciRec(m-1)); + } +} + +int main(){ + afficheFiboRec(15); + return 0; +} \ No newline at end of file diff --git a/DEV1.1/TP16:Recursivite/phases.c b/DEV1.1/TP16:Recursivite/phases.c new file mode 100644 index 0000000..60f5995 --- /dev/null +++ b/DEV1.1/TP16:Recursivite/phases.c @@ -0,0 +1,17 @@ +#include +#include + +void exemple(unsigned n) { + if (n != 0) { + putchar('>'); + exemple(n-1); + putchar('<'); + } else + putchar('O'); +} + +int main(){ + unsigned n=13; + exemple(n); + return 0; +} \ No newline at end of file diff --git a/DEV1.1/TP16:Recursivite/tableau.c b/DEV1.1/TP16:Recursivite/tableau.c new file mode 100644 index 0000000..4cf37e5 --- /dev/null +++ b/DEV1.1/TP16:Recursivite/tableau.c @@ -0,0 +1,20 @@ +#include +#include +#include + +void afficheTabRec(double tab[],int taille){ + if(taille==0){ + } afficheTabRec(tab, taille-1); + printf("%f, ",tab[taille-1]); +} + +int main(){ + int i; + double tab[15]=malloc(sizeof(double)); + srand(time(NULL)); + for (i=0;i<15;i++){ + tab[i]=(rand()%1000); + } + afficheTabRec(tab, sizeof(tab)); + return 0; +} \ No newline at end of file