C Programming Related Problem 11
Write down a C program Code to find out an item using Linear / Binary Search Technique.
Following Coding
#include<stdio.h>
int main()
{
int a[100];
int i,n,k,item;
printf("How many item do you want to insert:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Find out: ");
scanf("%d",&item);
k=0;
a[n+1]= item;
while(a[k]!=item)
{
k=k+1;
}
if(k==n+1)
{
printf("item is not found");
}
else
{
printf("%d is the location of item",k);
}
return 0;
}
Comments
Post a Comment