From c49b969659d8761442a560f8feda436bfb7b01e8 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 27 Mar 2025 17:24:15 +0100 Subject: Ajout des cours du 10 au 27 mars --- semestre 2/informatique/tme/semaine6/iter.c | 13 +++++++++++++ semestre 2/informatique/tme/semaine6/rec.c | 12 ++++++++++++ semestre 2/informatique/tme/semaine6/rec_2.c | 16 ++++++++++++++++ semestre 2/informatique/tme/semaine6/rec_str.c | 19 +++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 semestre 2/informatique/tme/semaine6/iter.c create mode 100644 semestre 2/informatique/tme/semaine6/rec.c create mode 100644 semestre 2/informatique/tme/semaine6/rec_2.c create mode 100644 semestre 2/informatique/tme/semaine6/rec_str.c (limited to 'semestre 2/informatique/tme/semaine6') diff --git a/semestre 2/informatique/tme/semaine6/iter.c b/semestre 2/informatique/tme/semaine6/iter.c new file mode 100644 index 0000000..fd55e23 --- /dev/null +++ b/semestre 2/informatique/tme/semaine6/iter.c @@ -0,0 +1,13 @@ +#include +int recherche_iter(int* arr, int n, int v) { + int i; + for (i = 0; arr[i] != v && i < n; i++); + if (i == n) return -1; + return i; +} + +int main() { + int arr[] = {1, 2, 3}; + printf("%d\n", recherche_iter(arr, 3, 4)); + return 0; +} 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 +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; +} 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 +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; +} diff --git a/semestre 2/informatique/tme/semaine6/rec_str.c b/semestre 2/informatique/tme/semaine6/rec_str.c new file mode 100644 index 0000000..a920af3 --- /dev/null +++ b/semestre 2/informatique/tme/semaine6/rec_str.c @@ -0,0 +1,19 @@ +#include +int est_deb(char* s1, char* s2) { + if (*s1 == '\0' || *s2 =='\0') return 1; + if (*s1 != *s2) return 0; + return est_deb(s1+1, s2+1); +} + +int est_incluse(char *sub, char* s) { + if (*s == '\0') return 0; + return est_deb(sub, s) ? 1 : est_incluse(sub, s+1); +} + +int main() { + printf("%d\n", est_deb("alpha", "alphabet")); + printf("%d\n", est_deb("alpaga", "alphabet")); + printf("%d\n", est_incluse("alp", "alphabet")); + printf("%d\n", est_incluse("apl", "alphabet")); + return 0; +} -- cgit v1.2.3