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

the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above

794


Who is the main contributor in designing the c language after dennis ritchie?

758


Why is sprintf unsafe?

799


What is a structure and why it is used?

839


What are all different types of pointers in c?

763


I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...

9906


What are the features of c languages?

821


What are local variables c?

739


What are enumerated types?

837


What do you mean by dynamic memory allocation in c? What functions are used?

879


Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me

1674


What does a function declared as pascal do differently?

797


What are c identifiers?

837


List some of the static data structures in C?

956


What is a floating point in c?

798