0% found this document useful (0 votes)
3 views1 page

Linear Search Using Recursion

The document presents a C program that implements a linear search algorithm using recursion. It prompts the user to input the size and elements of an array, as well as a key to search for. The program then recursively searches for the key in the array and outputs its position if found, or indicates that the element is not available.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Linear Search Using Recursion

The document presents a C program that implements a linear search algorithm using recursion. It prompts the user to input the size and elements of an array, as well as a key to search for. The program then recursively searches for the key in the array and outputs its position if found, or indicates that the element is not available.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

---- -----------------------------

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);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy