ProAnswers.org

Write a C program to perform searching the element in an Array ?

#include

#include 

void main() 

{ 

int j=0,n,x[5]; 

clrscr(); 

printf(“enter the elements of array

”);

for(j=0;j<5;j++) 

scanf(“%d”,&x[j]); 

printf(“enter the element to search

”);

scanf(“%d”,&n); 

for(j=0;j<5;j++) 

{ 

if(x[j]==n) 

break; 

} 

if(x[j]==n) 

printf(“element found”); 

else 

printf(“element not found”); 

getch(); 

} 

Output: 

enter the elements of array: 

1 

2 

3 

4 

5 

enter the elements to search 

3 

element found