=================================================== This is the code =================================================== #include<stdio.h> #include<string.h> #include<math.h> struct bs { int key; int l,h,m; int a[10]; }; typedef struct bs bs; int bin_s(bs); int main() { int i; bs b; printf("enter the data\n"); for(i=0; i<10;i++ ) scanf("%d",&b.a[i]); printf("enter the Key world\n"); scanf("%d",&b.key); b.l=0; b.h=9; b.m = bin_s(b); printf("data found:= %d\n",b.m); return -1; } int bin_s(bs b) { if(b.h > b.l) { b.m = b.l + ((b.h - b.l) / (b.a[b.h] - b.a[b.l])) * (b.key - b.a[b.l]); sleep(1); printf("b.m:= %d\n",b.m); if(b.key == b.a[b.m]) { return b.m; } else if(b.a[b.m] < b.key) { b.l=b.m + 1; b.m = bin_s(b); return b.m; } else { b.h= b.m - 1; b.m = bin_s(b); return b.m; }
} printf("key not found\n"); return -1; }
And the series:= ================================================ series ================================================ enter the data 1 3 5 7 9 11 15 16 17 18 enter the key value 12