C Program For Linear Recursion

#include<stdio.h>
#include<conio.h>
int a[5];
int linear(int num,int position)
{
if(num==a[position])
 {
return position;
 }
 else
 {
position++;
return linear(num,position);
 }
}
 void main()
 {
int i,n,ans;
clrscr();
printf("Enter The Numer Of Elements");
scanf("%d",&n);
printf("Enter array elements:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the number to be searched");
scanf("%d",&n);
ans=linear(n,0);
if(ans<=n)
 {
printf("number (%d) found at position (%d)",n,ans++);
 }
 else
 {
 printf("search element (%d) not found ",n);
 }
 getch();
 }
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment