C program to find an element from Array
Simple C program to find an element from Array
Code:
#include<stdio.h>#include<conio.h>
void main()
{
int a[20],i,x,n;
clrscr();
printf(“How many elements?”);
scanf(“%d”,&n);
printf(“Enter array elements:”);
for(i=0;i<n;++i)
scanf(“%d”,&a[i]);
printf(“nEnter element to search:”);
scanf(“%d”,&x);
for(i=0;i<n;++i)
if(a[i]==x)
break;
if(i<n)
printf(“Element found at index %d”,i);
else
printf(“Element not found”);
getch();
}
Comments
Post a Comment