Headlines
Loading...
C program to search an element in an array of n elements.

C program to search an element in an array of n elements.

Write a program to search an element in an array of n elements.

# include
# include
void main()
{
int a[50],n,i,s,flag=0;
clrscr();
printf("\nEnter the total numbeer of elements in the array:");
scanf("%d",&n);
for(i=0;i {
printf("\nEnter the value of %d:",i+1);
scanf("%d",&a[i]);
}
printf("\nEnter the value that has to be searched in the array:");
scanf("%d",&s);
for(i=0;i {
if(a[i]==s)
{
flag=1;
printf("\nValue Found in location %d",i+1);
break;
}
else
flag=0;
}
if(flag==0)
printf("Value not found");
getch();
}

/*Output
Enter the total numbeer of elements in the array:2

Enter the value of 1:66

Enter the value of 2:69

Enter the value that has to be searched in the array:69

Value Found in location 2

*/
*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***