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
What is the use of #define preprocessor in c?
What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file
How are structure passing and returning implemented?
What is 1f in c?
Which type of language is c?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????
How #define works?
What is the meaning of ?
What is the difference between variable declaration and variable definition in c?
in any language the sound structure of that language depends on its a) character set, input/output function, its control structures b) character set, library functions, input/output functions its control structures c) character set, library functions, control sturctures d) character set, operators, its control structures
Explain pointer. What are function pointers in C?
What is meant by keywords in c?
Compare array data type to pointer data type
Why is it important to memset a variable, immediately after allocating memory to it ?