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
How do I get an accurate error status return from system on ms-dos?
What is c++ used for today?
What is a MAC Address?
What are the different types of control structures in programming?
Explain what is the most efficient way to store flag values?
Explain what is gets() function?
write a progrmm in c language take user interface generate table using for loop?
What is the value of uninitialized variable in c?
What is the difference between pure virtual function and virtual function?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
What are comments and how do you insert it in a C program?
What is getch() function?
What are different storage class specifiers in c?
What is wrong in this statement? scanf(ā%dā,whatnumber);
define string ?