Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int main()
  5. {
  6. int flag,i,n,V[20],nombre_al,cpt;
  7.  
  8. flag=0;
  9. i=0;
  10. srand(time(NULL));
  11. for(cpt=0;cpt<20;cpt++)
  12. {
  13. nombre_al=rand()%(100 + 1);
  14. V[cpt]=nombre_al;
  15. }
  16.  
  17. printf("\nSaisir un nombre : ");
  18. scanf("%d",&n);
  19.  
  20. while(flag==0 && i<20)
  21. {
  22.  
  23. if(n==V[i])
  24. {
  25. flag=1;
  26. }
  27. else
  28. {
  29. i++;
  30. }
  31. }
  32. if(flag==0)
  33. {
  34. printf("\nLe nombre %d n'est pas dans le vecteur",n);
  35. }
  36. else
  37. {
  38. printf("\nLe nombre %d se trouve a l'indice %d",n,i+1);
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement