Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linear Search #438

Open
bca072024 opened this issue Jul 12, 2024 · 0 comments
Open

Linear Search #438

bca072024 opened this issue Jul 12, 2024 · 0 comments

Comments

@bca072024
Copy link

Write a c program to search a number with in an array using lenear & sequecnal search
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[30],n,i,pos,key;
int lsearch (int[],int,int);
printf("\nEnter no of elements");
scanf("%d",&n);
printf("\nEnter %d value",n);
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
printf("Enter key value");
scanf("%d",&key);
pos=lsearch (arr,n,key);
if(pos==-1)
printf("\n search no %d is not found",key);
else
printf("\n search no %d is found of index %d",key,pos);
}
int lsearch (int arr[],int n,int key)
{
int pos=-1,i;
for(i=0;i<n;i++)
{
if (arr[i]==key)
{
pos=i;
break;
}
}
return pos;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant