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