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 / ghost

#include<stdio.h>
#include<conio.h>

void main()
{
int a[100],i,element,temp,pos;

clrscr();
printf("enter the array elements\n");
for (i=0; i<5; i++)
scanf("%d",&a[i]);
printf("Enter the element to be search\n");
scanf("%d",&element);

// searching for the element

for (i=0; i<5; i++)
{
if (a[i]==element)
{
temp=1;
pos=++i;
}
}

if (temp==1)
printf("%d Element found at position==%d",element,pos);
else
printf("Element not found\n");
getch();

} // end of main()

Is This Answer Correct ?    13 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you understand by friend-functions? How are they used?

641


Can you pass an entire structure to functions?

690


When should structures be passed by values or by references?

581


What is main () in c?

584


Why c is a mother language?

552






Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?

749


What does static variable mean in c?

646


How can I read and write comma-delimited text?

616


How many levels deep can include files be nested?

646


What is output redirection?

687


What is a memory leak? How to avoid it?

569


What is the difference between text and binary i/o?

586


What is the return type of sizeof?

586


What is a pointer and how it is initialized?

605


What is atoi and atof in c?

612