Exercices
This commit is contained in:
commit
3cc0fb5e3c
40
main.c
Normal file
40
main.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user