Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Program to perform Linear Search

Program to perform Linear Search

August 20, 2012 Comments Off on Program to perform Linear Search By admin

Linear Search:

Linear search involves searching the element from a given set of elements beginning from the first element upto the last element or upto its first occurrence if it is available in the given set.  The efficiency of Linear Search is O(n).  The program to perform linear search is given below:

/* Linear Search */
#include <stdio.h>

#define MAX 10

int main(){
int arr[MAX],n,i,num,val;
printf(“nEnter total numbers?”);
scanf(“%d”,&n);
for(i=0;i<n;i++){
printf(“nEnter number?”);
scanf(“%d”,&arr[i]);
}
printf(“nEnter the value to search?”);
scanf(“%d”,&val);
for(i=0;i<n;i++){
if(arr[i]==val){
printf(“nNumber found.”);
return;
}
}
printf(“nNumber not found.”);
}

Comments are closed
x Close

Like Us On Facebook

You cannot copy content of this page.