Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. /* Program written by Mst. Sima Khatun */
  2. //linear search
  3.  
  4. #include<stdio.h>
  5.  
  6. int main()
  7. {
  8.     int n,i,item;
  9.     printf("Enter how many number you want to assign to the array \n");
  10.     scanf("%d",&n);
  11.     int num[n];
  12.     printf("enter %d number to the array \n",n);
  13.     for(i=0;i<n;i++)
  14.     {
  15.         scanf("%d",&num[i]);
  16.     }
  17.     printf("enter the num you want to search from the array \n");
  18.     scanf("%d",&item);
  19.  
  20.     for(i=0;i<n;i++)
  21.     {
  22.       if(item==num[i])
  23.       {
  24.          printf("item found in this list the index is %d \n",i);
  25.          return 0;
  26.       }
  27.     }
  28.     printf("item not found in this list\n");
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement