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
Tell me what is null pointer in c?
What is the advantage of an array over individual variables?
Can you write the algorithm for Queue?
What are the basic data types associated with c?
What functions are in conio h?
What is wrong with this initialization?
How can this be legal c?
What are different types of pointers?
What is the difference between near, far and huge pointers?
Explain how does free() know explain how much memory to release?
Explain what are reserved words?
Explain the use of #pragma exit?
When should a type cast be used?
How many levels of pointers can you have?
Differentiate between the expression “++a” and “a++”?