Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
accodes21 committed May 23, 2022
0 parents commit a64b871
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions LinearSearch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//Linear Search

#include <stdio.h>
int main(){
int a[10],i,x,n;
printf("No. of elements to enter:\n");
scanf("%d",&n);

printf("Enter elements:");
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}

printf("Array is :");
for(i=0;i<n;i++){
printf("%d",a[i]);
}

printf("\nElement to be searched:");
scanf("%d",&x);

for(i=0;i<n;i++){
if(a[i]==x)
break;
//printf("element found");
}

if(a[i]==x){
printf("Element found at %d",i+1);
}

else{
printf("Element not found");
}

return 0;

}

0 comments on commit a64b871

Please sign in to comment.