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
I need testPalindrome and removeSpace
#include
In which layer of the network datastructure format change is done
Is c still used?
How can you allocate arrays or structures bigger than 64K?
Why use int main instead of void main?
Differentiate between the expression “++a” and “a++”?
What is structure packing in c?
all c language question
Explain null pointer.
Compare and contrast compilers from interpreters.
What is openmp in c?
What is a double c?
What is chain pointer in c?
Why is c still so popular?
What are data types in c language?