Program to perform Linear Search

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.”);
}