Friday, 15 May 2015

Binary Search In C

Binary Search In C


Problem Statement:  write binary search code in c, that will search for the number in array and find output if the number is found and also print how many times the number is found.

#include<stdio.h>
#include<conio.h>
int main()
{
int i,A[5],num,found=0;
for(i=1;i<=5;i++)
{
printf("Enter the numbers into array");
scanf("%d",&A[i]);
}
printf("Enter the number you required");
scanf("%d",&num);
for(i=1;i<=5;i++)
{
 if(num==A[i])
 {
  found++;
}
}
if(found>=1)
printf("The element is %d times found",found);
else
printf("The element is not found");
getch();
}

0 comments:

Post a Comment