#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();
}
#include<conio.h>
#include<stdio.h>
void main()
{
int n,a[100],i,j,k,t,*p,*beg,*last,*mid,elmnt;
char ch;
clrscr();
printf("Enter no of elements : ");
scanf("%d",&n);
printf("\nEnter the elmnts :\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
p=a;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(*(p+i)>*(p+j))
{
t=*(p+i);
*(p+i)=*(p+j);
*(p+j)=t;
}
}
}
do{clrscr();
printf("\nSorted Array is:\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
beg=&a[0];
last=&a[n-1];
printf("\nEnter element to be searched for : ");
scanf("%d",&elmnt);
while(*mid!=elmnt&&beg<=last)
{mid=beg+(last-beg)/2;
if(*mid<elmnt)
beg=mid+1;
if(*mid>elmnt)
last=mid-1;
}
if(*mid==elmnt)
printf("\nElement %d found ",elmnt);
else printf("\nElement not found ");
printf("\n\nPress <y> to search for another element..");
ch=getch();
}while(ch=='y');
}
----------------------------------------------------------------------------
Mithu
The best search programs to attempt writing in C are the following: Linear search (simplest), Binary search (faster) Hash search (fastest).
write a c++ program to convert binary number to decimal number by using while statement
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.
brown
(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).
i want to know how to give the algorithm password in a computer ?
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 > value at root 3.values in left subtree < value at root 4.left,right subtrees must be binary search trees
The best search programs to attempt writing in C are the following: Linear search (simplest), Binary search (faster) Hash search (fastest).
cg code for binary tree
write a c++ program to convert binary number to decimal number by using while statement
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.
brown
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
(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).
Example: void foo( MyClass& object ){} // function with call by reference signature MyClass* p = new MyClass(); // instantiate a pointer to MyClass foo( *p ); // call by reference using the pointer
By using a compiler.
write a c program that takes a binary file as input and finds error check using different mechanisms.