61. WRITE A C PROGRAM FOR LINEAR SEARCH IN AN ARRAY

/*C program for linear search in an array*/

#include<stdio.h>
#include<conio.h>
int main()
{
int num[10],key,found=0,=0;
clrscr();
printf(“enter the key value\n”);
for(i=0;i<10;i++)
{
scanf(“%d”,num[i]);
}
printf(“enter the key value\n”);
scanf(“%d”,key);
for(i=0;i<10;i++)
if(num[i]==key)
{
found==1;
printf(“% delement found at %d\n”,key);
}
if(found==0);
printf(“the element is not found ”);
getch();
return 0;
}

output

enter the values
1
2
3
4
5
6
7
8
9
enter the key value 5
5 element found at 5 position

Comments