#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();
}
#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();
}
No comments:
Post a Comment