Advertisement
JayaAhmed

Linear Search

Jul 5th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int array[100];
  6.     int i, num, key, found = 0;
  7.  
  8.     printf("Enter the value of num : ");
  9.     scanf("%d", &num);
  10.     printf("Enter the elements : ");
  11.  
  12.     for (i = 0; i < num; i++)
  13.     {
  14.         scanf("%d", &array[i]);
  15.     }
  16.  
  17.     printf("Enter the element to be searched : ");
  18.     scanf("%d", &key);
  19.  
  20.     for (i = 0; i < num ; i++)
  21.     {
  22.         if (key == array[i] )
  23.         {
  24.             found = 1;
  25.             break;
  26.         }
  27.     }
  28.  
  29.     if (found == 1)
  30.         printf("Element is present in the array\n");
  31.     else
  32.         printf("Element is not present in the array\n");
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement