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 / sunil makwana

#include<stdio.h>
#include<conio.h>
void searchval(int a[5],int n)
{
int i,temp=0,pos=0;

for (i=0; i<5; i++)
{
// printf("value of array:: %d",i);
if (a[i]==n)
{
temp=1;
pos=i;
}
}
if (temp==1)
{

printf("Element found %d , position==%d",n,pos);
}
else
{
printf("Element not found\n");
}




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

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);

searchval(a,ele);
getch();
}

Is This Answer Correct ?    29 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I get an accurate error status return from system on ms-dos?

641


What is c++ used for today?

659


What is a MAC Address?

624


What are the different types of control structures in programming?

656


Explain what is the most efficient way to store flag values?

692






Explain what is gets() function?

623


write a progrmm in c language take user interface generate table using for loop?

1571


What is the value of uninitialized variable in c?

566


What is the difference between pure virtual function and virtual function?

643


Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.

663


What are comments and how do you insert it in a C program?

737


What is getch() function?

643


What are different storage class specifiers in c?

611


What is wrong in this statement? scanf(ā€œ%dā€,whatnumber);

722


define string ?

662