Skip to content

Instantly share code, notes, and snippets.

Last active August 6, 2017 15:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
C Program to demonstrate the working of linear search. We take an array of integers and search it for a given key.
#include <stdio.h>
#include <conio.h>
void main()
int array[10];
int i, N, keynum, found=0;
printf("Enter the value of N\n");
printf("Enter the elements one by one\n");
for(i=0; i<N ; i++)
printf("Input array is\n");
for(i=0; i<N ; i++)
printf("Enter the element to be searched\n");
scanf("%d", &keynum);
for ( i=0; i < N ; i++)
if( keynum == array[i] )
found = 1;
if ( found == 1)
printf("Element found in the given array");
printf("Element was not found in the array");
} /* End of main */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment