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();
}

Related Posts:

  • C code to implement stack Problem Statement: Write a program in c language to implement stack operation. i) Push ii) Pop iii)Top iv) Display Code: #include<conio.h> … Read More
  • Semester Project For C Language Here is a letter guessing game in c language. You can use this code as your semester project. First enter the word and your name. It will ask you w… Read More
  • 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 … Read More
  • C Program To Print Chess Board Problem Statement: Write a program in c that will print the chess board. Enter a number to print the board. #include<stdio.h> #include<… Read More
  • Program To Print Factorial In C Problem Statement: Write a program in c that will print the factorial of a given number using for loop. #include<stdio.h> #include<conio… Read More

0 comments:

Post a Comment