Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #14 from anshullahoti/linear_search
Browse files Browse the repository at this point in the history
Added linear search in C #1
  • Loading branch information
ayan-b authored Oct 16, 2017
2 parents 02ec5e3 + 99c93a1 commit 0b20a66
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions linearsearch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<stdio.h>
int main()
{
int n,i,x,flag=0;
int a[100100];
scanf("%d",&n); //how many numbers in which you want to search
for(i=0;i<n;i++)
{
scanf("%d",&a[i]); //Taking input from user
}
scanf("%d",&x); // Number which we want to search
for(i=0;i<n;i++)
{
if(a[i]==x)
{
flag=1; //If number is found then set the flag
}
}
if(flag==1)
printf("Yes\n"); //If number is found then print yes.
else
printf("No\n"); // If number is not there then print no.
return 0;
}

0 comments on commit 0b20a66

Please sign in to comment.