diff options
Diffstat (limited to 'semestre 2/informatique/tme/semaine6/rec_str.c')
| -rw-r--r-- | semestre 2/informatique/tme/semaine6/rec_str.c | 19 |
1 files changed, 19 insertions, 0 deletions
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 <stdio.h> +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; +} |
