commit 3cc0fb5e3c10f757505de89715b5f4dca38fffbf Author: Alexandre Date: Mon Feb 24 13:29:02 2025 +0100 Exercices diff --git a/main.c b/main.c new file mode 100644 index 0000000..4b30fd7 --- /dev/null +++ b/main.c @@ -0,0 +1,40 @@ +#include +#include + +// Variables +const int size=8; +int *alloc_tab(){ + int *tab=NULL; + tab=malloc(sizeof(int)*size); + tab[0]=4; + tab[1]=2; + tab[2]=5; + tab[3]=5; + tab[4]=5; + tab[5]=20; + tab[6]=910; + tab[7]=91; + return tab; +} + +void in_tab(int tab[], int cible) { + int occurence=0; + for (int i=0; i < size; i++) { + if (tab[i] == cible) { + printf("La cible se trouve dans le tableau\n"); + occurence++; + } + else { + printf("La cible ne se trouve pas dans le tableau\n"); + } + } + if (occurence!=0) { + printf("La cible est dans le tableau, %d fois", occurence); + } +} +int main(void) { + int* tab=alloc_tab(); + in_tab(tab, 5); + free(tab); + return 0; +} \ No newline at end of file