C program for Linear or Sequential Search.

#include<stdio.h>
#include<conio.h>
#define N 5
void main(){
int list[N],i,item;
clrscr();
printf("Enter Elements of List Array\n");
for(i=0;i<N;i++){
printf("Enter %d Element = ",i+1);
scanf("%d",&list[i]);
}
printf("Enter an item to Search\n");
scanf("%d",&item);
for(i=0;i<N;i++){
if(item==list[i]){
printf("Searching is Successful\n %d is found at %d Index and %d Position \n",item,i,i+1);
getch();
exit(0);
}}
printf("Searching is Unsuccessful\n %d is not found\n",item);
getch();
}

No comments:

Post a Comment