Search an Element in Array

#include<stdio.h> #include<conio.h> void main()
{
int a[50],i,se,n,found=0;
clrscr();
printf(“\n Enter the total elements in a an array = “);
scanf(“%d”,&n);
printf(” Enter the array elements = “);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(” Enter the element is to be searched = “);
scanf(“%d”,&se);
i=0;
while(i<=n && found==0)
{
if(a[i]==se)
found=1;
i++;
}
if(found==1)
{
printf(” Element found at position %d.”,i);
}
else
{
printf(” Element not found. “);
}
getch();
}

Posted in: C

Leave a Reply

Your email address will not be published. Required fields are marked *