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


Please Help Members By Posting Answers For Below Questions

Tell me what is null pointer in c?

611


What is the advantage of an array over individual variables?

732


Can you write the algorithm for Queue?

1546


What are the basic data types associated with c?

811


What functions are in conio h?

652






What is wrong with this initialization?

585


How can this be legal c?

648


What are different types of pointers?

561


What is the difference between near, far and huge pointers?

628


Explain how does free() know explain how much memory to release?

569


Explain what are reserved words?

630


Explain the use of #pragma exit?

694


When should a type cast be used?

573


How many levels of pointers can you have?

695


Differentiate between the expression “++a” and “a++”?

697