Array Search (Linear search)

C program to search a particular number in an array.


#include <stdio.h>
int main()
{
 int arr[10]={3,5,4,7,8,1,12,18,6,10};
 int n,i,found=0;

 printf("Enter a number you want to search : ");
 scanf("%d",&n);

 for(i=0;i<10;i++)
 {
   if(arr[i] == n)
   {
    found = 1;
    break;
   }
 }

 if(found == 1)
   printf("YES, Number is present in the array");
 else
   printf("No, Number is NOT present in the array");

 return 0;
}

OUTPUT:
(1st RUN)
Enter a number you want to search : 7
YES, Number is present in the array

(2nd RUN)
Enter a number you want to search : 9
No, Number is NOT present in the array

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.