answersLogoWhite

0

#include
#include
#include
void main()
{
int a[10]={1,2,3,10,11,13,16,21,46,73};
int mid,lower=0,upper=9,num,flag=1;
clrscr();
printf("enter the number to search");
scanf("%d",&num);
printf("\n the list of the data is");
printf("%-20s","\ndata);
for(num=0;num<=upper;num++)
printf("%3d",a[num]);
printf("%-20s","\nindexno");
for(num=0;num<=upper;num++)
printf("%3d",num);
for(mid=(lower+upper)/2;lower<=upper;mid=(lower+upper)/2)
{
if(a[mid]==num)
{
printf("the number is at position %d in array",mid);
flag=0;
break;
}
if(a[mid]>num)
upper=mid-1;
else
lower=mid+1;
}
if(flag)
printf("element is not present in the array");
getch();
}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Give you the algorithm of creating a new binary search tree using c?

i want to know how to give the algorithm password in a computer ?


What is binary search in data structure using c?

a tree which has atmost two nodes is called binary tree binary search tree is a binary tree which satisfies the following 1.every node in tree must be distinct 2.values in right subtree &gt; value at root 3.values in left subtree &lt; value at root 4.left,right subtrees must be binary search trees


Best first search program in c?

The best search programs to attempt writing in C are the following: Linear search (simplest), Binary search (faster) Hash search (fastest).


Code for binary trees written in C using graphics?

cg code for binary tree


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


What is NULL array in C Language?

There is no "NULL array" as such, you may take a pointer to an array and set it to NULL (binary 0) e.g. int* foo; // Declare a pointer foo = malloc( 40 * sizeof(int)); //Allocate an array of 40 integers pointed to by "foo" foo = NULL; //Set the pointer to NULL, if you're using a garbage collector this should trigger an automatic free() of the memory allocated to the array. If you are NOT using a garbage collector (which is more common in C) this line is a memory leak.


How do you change scrin coulor using far pointer in c ganguage?

brown


What is a tree recursion in C programming?

A binary tree is made of nodes, where each node contains a "left" pointer, a "right" pointer, and a data element. The "root" pointer points to the topmost node in the tree. The left and right pointers recursively point to smaller "subtrees" on either side. The formal recursive definition is: a binary tree is either empty (represented by a null pointer), or is made of a single node, where the left and right pointers (recursive definition ahead) each point to a binary tree. Tree recursion describes a class of algorithms for accessing binary trees, exploiting their inherently recursive nature. answer by narayan nyaupane kathmandu, Nepal


What are the Advantages of binary search on linear search in c?

(i) Binary search can interact poorly with the memory hierarchy (i.e. caching), because of its random-access nature. For in-memory searching, if the interval to be searching is small, a linear search may have superior performance simply because it exhibits better locality of reference. (ii) Binary search algorithm employs recursive approach and this approach requires more stack space. (iii) Programming binary search algorithm is very difficult and error prone (Kruse, 1999).


Call by reference using pointer in c plus plus?

Example: void foo( MyClass&amp; object ){} // function with call by reference signature MyClass* p = new MyClass(); // instantiate a pointer to MyClass foo( *p ); // call by reference using the pointer


What are the different types of files and how End Of File of a full represented by a pointer?

There are two file types in C++ namely, text file and binary file. In text file EOF or end of file is represented by an end of file character having ASCII 26. In binary files EOF or end of file is represented by NULL in the file pointer


How is the code return in higher programming languages like C and C converted into binary language?

By using a compiler.