---- -----------------------------
LINEAR SEARCH USING RECURSION
------------------------------
#include<stdio.h>
#include<conio.h>
int linearsearch(int a[],int key,int i,int n);
int main()
{
int a[40],n,i,key,flag=0;
printf("\n enter the size of the array::");
scanf("%d",&n);
printf("\n enter the elements of the array::");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n enter the key:");
scanf("%d",&key);
flag=linearsearch(a,key,0,n);
if(flag!=0)
{
printf("\n element is available at %d place",flag);
}
else
{
printf("\n element is not available place");
}
return 0;
}
int linearsearch(int a[],int key,int i,int n)
{
if(i>=n)
{
return 0;
}
else if(a[i]==key)
{
return i;
}
else
{
return linearsearch(a,key,i+1,n);
}
}