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
write a program to find out prime number using sieve case?
What is the general form of function in c?
A text file that contains declarations used by a group of functions,programs,or users a) executable file b) header file c) obj file d) .cfile
Write a program to use switch statement.
Define and explain about ! Operator?
Write a program to identify if a given binary tree is balanced or not.
What is double pointer?
explain what is a newline escape sequence?
What do you understand by normalization of pointers?
Why do we use main function?
Wt are the Buses in C Language
How can I implement a delay, or time a users response, with sub-second resolution?
Did c have any year 2000 problems?
A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(
Explain continue keyword in c