/* 11(b) W.A.P. in C to input n numbers and conduct a linear search for a given key number and report success or failure. */
#include<stdio.h>
void main()
{
int i,n,*res,find,*pos,pstart=0; /* Variable Declarations */
clrscr();
printf("How many elements you want to type in the list : ");
scanf("%d",&n);
if (n>0)
{
printf("Enter %d numbers of the list\n\n",n);
for (i=0; i<n; i++)
{
scanf("%d",&res[i]);
}
printf("\n\nEnter the element to be searched in the above list : ");
scanf("%d",&find);
/* Search the element in the list */
for (i=0; i<=n; i++)
{
if (find==res[i])
{
pos[pstart++]=(i+1);
}
}
if (pstart>0) /* Element found in the list */
{
printf("\n******* Search Successfull *******\n");
printf("Element found %d time(s) in the above list\n",pstart);
for (i=1; i<=pstart; i++)
{
printf("\nposition-%d is %d",i,pos[i-1]);
}
getch();
exit(0);
}
else /* Element not found in the list */
printf("\n******* Search Failure *******\n");
printf("Sorry! Element not found in the above list. Try Later");
}
else printf("\n!!! Invalid Input Entry !!!");
getch();
}