#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int main() {
int taille,x;
printf("veuillez entrer la taille\n");
scanf("%d",&taille);
int tab[taille];
srand(time(NULL));
tab[0]=rand()%(taille+1);
for(int i=1;i<taille;i++) {
tab[i]=tab[i-1]+rand()%(taille+1);
}
for(int i=0;i<taille;i++){
printf("i %d = ",i);
printf("%d\n",tab[i]);}
printf("veuillez entrer votre valeur\n");
scanf("%d",&x);
int milieu ;
int debut=0,fin=taille-1;
while(debut<=fin){
milieu=(debut+fin)/2;
if (x == tab[milieu]) {
printf("la valeur est presenter dans le taleau");
return 0;}
if (x <tab[milieu]) {fin=milieu-1;}
else{
debut=milieu+1; }
}
printf("la valeur n'exicte pas dans le tableau ");
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: