Created
July 26, 2017 15:08
-
-
Save sujaykundu777/d2841c85a65b8ca4ed09c765698e8125 to your computer and use it in GitHub Desktop.
Linear Search Algorithm Implementation in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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