Tuesday, January 17, 2012

Searching the Element in an Array


#include<stdio.h>
#include<conio.h>
void main()
{
int j=0,n,x[5];
clrscr();
printf(“enter the elements of array\n”);
for(j=0;j<5;j++)
scanf(%d”,&x[j]);
printf(“enter the element to search\n”);
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

No comments:

Post a Comment