Linear search program using c
Linear search program
#include<stdio.h>#include<conio.h>
void main()
{
int n,key,flag=1,i,a[10];
clrscr();
printf("Enter the number of elements in array");
scanf("%d",&n);
printf("Enter the elements:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the elements to be searched:");
scanf("%d',&key);
for(i=0;i<n;i++)
{
if a[i]==key;
{
flag=0;
}
}
if(flag==0)
{
printf(" The elements is found");
}
else
{
printf("the elements is not found"):
}
getch();
}
Output
Enter the number of elements:3Enter the elements:
12
85
90
Enter the elements to be searched:85
The element is found
No comments: