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

WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..

1605


What is the difference between a free-standing and a hosted environment?

653


What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?

964


What is the difference between c and python?

592


When do we get logical errors?

646






Can stdout be forced to print somewhere other than the screen?

633


Is there sort function in c?

587


Write a program of prime number using recursion.

631


Is c weakly typed?

585


can any one provide me the notes of data structure for ignou cs-62 paper

1716


What is a program flowchart and how does it help in writing a program?

679


What does sizeof int return?

601


How to write a multi-statement macro?

631


What is the difference between char array and char pointer?

537


What are the features of the c language?

656