diff options
Diffstat (limited to 'semestre 2/informatique/tme/semaine6/rec.c')
| -rw-r--r-- | semestre 2/informatique/tme/semaine6/rec.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/semestre 2/informatique/tme/semaine6/rec.c b/semestre 2/informatique/tme/semaine6/rec.c new file mode 100644 index 0000000..0a5bb34 --- /dev/null +++ b/semestre 2/informatique/tme/semaine6/rec.c @@ -0,0 +1,12 @@ +#include <stdio.h> +int recherche_rec(int* arr, int n, int v){ + if (n == 0) return -1; + if (arr[n-1] == v) return n-1; + return recherche_rec(arr, n-1, v); +} + +int main() { + int arr[] = {1, 2, 3, 5, 5}; + printf("%d\n",recherche_rec(arr, 5, 6)); + return 0; +} |
