From 3741430615c04604431aa059d5c5048464434dc0 Mon Sep 17 00:00:00 2001 From: Simon Saye Babu Date: Wed, 14 Dec 2022 15:29:55 +0100 Subject: [PATCH] recur --- DEV1.1/TP14/curiosité.c | 20 ++++++++++++++++++++ DEV1.1/TP14/fibo.c | 32 ++++++++++++++++++++++++++++++++ DEV1.1/TP14/phases.c | 17 +++++++++++++++++ DEV1.1/TP14/tableau.c | 24 ++++++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 DEV1.1/TP14/curiosité.c create mode 100644 DEV1.1/TP14/fibo.c create mode 100644 DEV1.1/TP14/phases.c create mode 100644 DEV1.1/TP14/tableau.c diff --git a/DEV1.1/TP14/curiosité.c b/DEV1.1/TP14/curiosité.c new file mode 100644 index 0000000..41d8c35 --- /dev/null +++ b/DEV1.1/TP14/curiosité.c @@ -0,0 +1,20 @@ +#include +#include + +int f(int n) +{ + if(n>100) + { + return n-10; + } + else + { + return f(f(n+11)); + } +} + +int main(int argc, char const *argv[]) +{ + printf("%d\n",f(201)); + return 0; +} \ No newline at end of file diff --git a/DEV1.1/TP14/fibo.c b/DEV1.1/TP14/fibo.c new file mode 100644 index 0000000..5d4ff69 --- /dev/null +++ b/DEV1.1/TP14/fibo.c @@ -0,0 +1,32 @@ +#include +#include + +int fibonacci(int n) +{ + if (n <= 1) + { + return 1; + }else + { + return(fibonacci(n-1)+fibonacci(n-2)); + } +} + +void fibonacci2(int n) +{ + if (n!=0) + { + fibonacci2(n-1); + printf("%d\n",fibonacci(n)); + } +} + + +int main(int argc, char const *argv[]) +{ + /*printf("%d\n", fibonacci(5));*/ + fibonacci2(4); + printf("%d",!0); + return 0; + +} \ No newline at end of file diff --git a/DEV1.1/TP14/phases.c b/DEV1.1/TP14/phases.c new file mode 100644 index 0000000..18945b7 --- /dev/null +++ b/DEV1.1/TP14/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(int argc, char const *argv[]) +{ + exemple(5); + return 0; +} \ No newline at end of file diff --git a/DEV1.1/TP14/tableau.c b/DEV1.1/TP14/tableau.c new file mode 100644 index 0000000..8fcb50d --- /dev/null +++ b/DEV1.1/TP14/tableau.c @@ -0,0 +1,24 @@ +#include +#include + +void pTab(double tablax[],int i) +{ + if (i>=0) + { + if (i==0) + { + printf("%.2lf\n", tablax[i]); + }else + { + printf("%.2lf ,", tablax[i]); + pTab(tablax,i-1); + } + } +} + +int main(int argc, char const *argv[]) +{ + double tablo[5]={1,2,3,4,5}; + pTab(tablo,(sizeof(tablo)/sizeof(tablo[0]))-1); + return 0; +} \ No newline at end of file