Thursday, 21 July 2011

Program to Search an Element in the Array using Linear Search in c

Do you like this post?
#include
#include
void main()
{
int a[10], i, item;
printf("\nEnter elements of an array:\n");
for (i=0; i<=9; i++) scanf("%d", &a[i]); printf("\nEnter item to search: "); scanf("%d", &item); for (i=0; i<=9; i++) if (item == a[i]) { printf("\n\n Item found at location %d", i+1); break; } if (i > 9)
printf("\n\n Item did not exist.");
getch();
}

No comments:

Post a Comment