You can perform a search for array element based on its value or its index.
Consider LA is a linear array with N elements and K is a positive integer such that K<=N.
//Write a program to perform Search operation.
#include <stdio.h>
void main()
{
int LA[] = {2,4,6,8,9};
int item = 6, n = 5;
int i = 0, j = 0;
printf("The original array elements are:\n");
for(i = 0; i<n; i++)
{
printf("LA[%d] = %d \n", i, LA[i]);
}
while( j < n)
{
if( LA[j] == item )
{
break;
}
j = j + 1;
}
printf("Found element %d at position %d\n", item, j+1);
}
Ask Question