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 / bishwas bidari

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

void main()
{
int a[5],i;
int ele,temp=0,pos=0;

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",&ele);

/* searching for the element*/

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

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

Is This Answer Correct ?    85 Yes 52 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are c preprocessors?

911


can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......

1625


How does free() know explain how much memory to release?

811


Is a house a shell structure?

906


What is 1f in c?

2288


Why we not create function inside function.

1965


What is array in c with example?

867


Where can I get an ansi-compatible lint?

881


What is extern variable in c with example?

756


How can you find out how much memory is available?

802


How to draw the flowchart for structure programs?

8970


Explain the difference between ++u and u++?

835


I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.

1951


How does selection sort work in c?

806


When should you use a type cast?

807