write a program to search for an element in a given array.
If the array was found then display its position otherwise
display appropriate message in c language

Answer Posted / mr. x

#include<stdio.h>
#include<conio.h>
void main ()
{
int a[5],b,c,i;
clrscr();
printf("
Enter no. of elements: ");
scanf("%d",&c);
i=0;
while(i<c)
{
scanf("%d",&a[i]);
i++;
}
printf("
Enter the elements to be searched: ");
scanf("%d",&b);
i=0;
while(i<c &b!=a[i])
{
i++;
}
if (i<c)
{
printf("number found");
i++;
}
else
{
printf(" number not found");
}
getch();
}

Is This Answer Correct ?    8 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does stand for?

826


Can a function argument have default value?

897


What does char * * argv mean in c?

799


What is auto keyword in c?

957


What is union and structure in c?

843


any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above

819


Why string is used in c?

747


What type is sizeof?

787


Why should I use standard library functions instead of writing my own?

951


Can you please compare array with pointer?

816


What is preprocessor with example?

776


How can you pass an array to a function by value?

826


What is the need of structure in c?

776


How are structure passing and returning implemented?

769


write a program to print data of 5 five students with structures?

1824