Skip to content

Instantly share code, notes, and snippets.

@sujaykundu777
Created July 26, 2017 15:08
Show Gist options
  • Save sujaykundu777/d2841c85a65b8ca4ed09c765698e8125 to your computer and use it in GitHub Desktop.
Save sujaykundu777/d2841c85a65b8ca4ed09c765698e8125 to your computer and use it in GitHub Desktop.
Linear Search Algorithm Implementation in C
#include<stdio.h>
int main (){
int count=0;
int i,size;
int key;
int a[100];
printf("Enter the size of the array");
scanf("%d",&size);
printf("Enter the Elements :");
for(i=0;i<size;i++){
scanf("\n %d",&a[i]);
}
printf("Enter the Element You Want To Search ");
scanf("%d",&key);
for(i=0;i<size;i++){
if(a[i] == key) {
printf("%d is present at location %d \n",key , i+1);
count++;
}
}
if( count==0){
printf("Element Not Found !");
}
else{
printf("%d is present %d times in a array \n",key,count);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment