Advertisement
lidia_defreitas

Exemplo pesquisa sequencial

Jul 4th, 2016
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.    
  5.     int vetor[10] = { 60, 50, 20, 40, 30, 80, 10, 90, 70, 100};
  6.     int i, num;
  7.     int encontrou = 0;
  8.        
  9.     printf("Informe um numero: ");
  10.     scanf("%d", &num);
  11.    
  12.  
  13. ///// tá errado, tem q ser while
  14. enquanto i < 10 encontrou == 0
  15.     for(i = 0; i < 10; i++){
  16.         if(num == vetor[i]){
  17.             encontrou = 1;
  18.  
  19.             break;
  20.         }
  21.     }
  22.    
  23.     if(encontrou == 1){
  24.         printf("\nnumero encontrado\n");       
  25.     }else{
  26.         printf("\nnumero não encontrado\n");      
  27.     }
  28.    
  29.    
  30.     system("pause");
  31.    
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement