#include <stdio.h>
#include <string.h>
void main()
{
int a[13]={12, 23, 30, 32, 38, 42, 50, 60, 65, 70, 85, 90, 100};
int i, start, end, mid, key;
start = 0;
end = 12;
key= 32;
do{
mid=(int)((start+end)/2);
printf("Start : %d\t End : %d\t Mid : %d\t Key %d\t a[mid]:%d\n", start, end, mid, key, a[mid]);
if(a[mid]==key){
printf("Find at %d\n", mid+1);
break;
}
else if(a[mid]>key){
end=mid-1;
}
else{
start=mid+1;
}
}
while(start <= end);
if(start>end)
printf("Failed\n");
}
#include <string.h>
void main()
{
int a[13]={12, 23, 30, 32, 38, 42, 50, 60, 65, 70, 85, 90, 100};
int i, start, end, mid, key;
start = 0;
end = 12;
key= 32;
do{
mid=(int)((start+end)/2);
printf("Start : %d\t End : %d\t Mid : %d\t Key %d\t a[mid]:%d\n", start, end, mid, key, a[mid]);
if(a[mid]==key){
printf("Find at %d\n", mid+1);
break;
}
else if(a[mid]>key){
end=mid-1;
}
else{
start=mid+1;
}
}
while(start <= end);
if(start>end)
printf("Failed\n");
}
একটি মন্তব্য পোস্ট করুন