Search Your Query

Breaking

Friday, June 7, 2019

Linear Searching


Linear Searching

Program Code :

#include<stdio.h>
#include<stdlib.h>
int main()
{
int *a,i,n,k,flag=0;
printf("Enter the value of array\n");
scanf("%d",&n);
a=(int*)malloc(n*sizeof(int));
printf("Enter the elements\n");
for(i=0;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter your searching number\n");
scanf("%d",&k);
for(i=0;i<=n;i++)
{
if(a[i]==k)
{
printf("Your number is found\n");
flag=1;
break;

}
}
if(flag==0)
{
printf("Your number not found\n");
}
return 0;

}

Hence , coming soon //

Input :

Enter the size of array
5
Enter the elements of array
1
2
3
4
5
6
Enter your searching number
7

Output :

Your number not found

Input :

Enter your searching number
5

Output :

Your number is found

No comments:

Post a Comment