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 / kapil hansrajani
include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,j,n;
clrscr();
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element to search : ");
scanf("%d",&j);
for(i=0;i<n;i++)
{
if(a[i]==j)
{
printf("The position of the element %d is %d ",j,i);
break;
}
}
getch();
}
| Is This Answer Correct ? | 48 Yes | 26 No |
Post New Answer View All Answers
How can I find out how much free space is available on disk?
What do you mean by recursion in c?
What are the advantages and disadvantages of a heap?
What is difference between union All statement and Union?
What are the main characteristics of c language describe the structure of ac program?
An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above
What does sizeof int return?
Do you have any idea about the use of "auto" keyword?
Can main () be called recursively?
Write a program to check armstrong number in c?
any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above
Why void is used in c?
what is the height of tree if leaf node is at level 3. please explain
How do you construct an increment statement or decrement statement in C?
Compare interpreters and compilers.