Linear search

Program to search for a key element in an entered array using Linear search [Recursively]


#include<stdio.h>
#include<conio.h>
int count=0,key,n;
main()
{
void lin_srch(int *,int);
int i,a[10];
clrscr();
printf("\nEnter the no of elements : ");
scanf("%d",&n);
printf("\nEnter the array elements \n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nEnter the element to be searched : ");
scanf("%d",&key);
i=0;
lin_srch(a,i);
if(count==0)
printf("\nElement not found in the array..!");
else
printf("\n%d found in the array!! \nCount = %d",key,count);
getch();
return 0;
}

void lin_srch(int a[],int i)
{
if(i==n-1)
return;
if(a[i]==key)
{
count++;
}
lin_srch(a,i+1);
}
Category:

0 comments: