Google analytics

Wednesday, February 1, 2012

To search a given number from a given list of numbers entered using liner serach??


#include<stdio.h>
#include<conio.h>
void main()
{
int a[20];
int n,i,item,loc,count=0;
clrscr();
printf("\n Enter number of elements : ");
scanf("%d",&n);
printf("\n Enter numbers : ");
for(i=1;i<=n;i++)
{
scanf("%d", &a[i]);
}
printf("\n Enter item to be searched : ");
scanf("%d", &item);
for(i=1;i<=n;i++);
{
if (a[i] == item)
{
loc=i;
printf("\n %d present at loc %d",item,loc);
count++;
}
}
if (count != 0)
{
printf("\n The number is present %d times",count);
}
else
printf("\n Item is not present");
getch();
}

No comments:

Post a Comment