Friday, October 14, 2011

Write a C program to find given element in a list or not.(linear search)?

#include
main()
{
int a,b,c,d,e=0;
printf("\nEnter the length of your list = ");
scanf("%d",&a);
int list[a];
for (b=1;b<=a;b++)
{
printf("\nElement%d:",b);
scanf("%d",&list[b]);
}
printf("\nEnter a Element you want search:\t");
scanf("%d",&c);
for (d=1;d<=a;d++)
{
if (list[d]==c)
e=e+1;
}
if (e==0)
printf("*****The given input element not found*****");
else
printf("\nThe given element present %d time(s) in the list.\n",e);
}

No comments:

Post a Comment