Advertisement
rafikamal

Search a number

Jan 17th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int a[100];
  6.     int n, i, m;
  7.     int position;
  8.    
  9.     printf("How many numbers?\n");
  10.     scanf("%d", &n);
  11.    
  12.     for(i = 0; i < n; i++)
  13.     {
  14.         printf("Enter number %d: ", i+1);
  15.         scanf("%d", &a[i]);
  16.     }
  17.    
  18.     printf("Enter the number you want to search: ");
  19.     scanf("%d", &m);
  20.    
  21.     for(i = 0; i < n; i++)
  22.         if(a[i] == m)
  23.         {
  24.             position = i;
  25.             break;
  26.         }
  27.        
  28.     if(position == n)
  29.         printf("Number not found\n");
  30.     else
  31.         printf("%d found at position %d\n", m, position);
  32.    
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement