![]() |
C++ assignment
Hi all
Please help me to solve this problem. i tried to solve this problem many times. but i couldnt do that. so please look at my code & help me to code this correctly. thanks Write a C++ program that will call a function that performs Binary Search on a sorted array. [You could use the binary search function provided in the class notes for this task.] The value to be searched for is: 12.5 float array2 = { 2.3, 4.8, 5.1, 6.8, 7.6, 8.3, 10.2, 11.4, 12.5, 18.9, 27.3 } The code need to correct Code: Code:
#include <iostream.h> |
Re: C++ assignment
try setting middle to ZERO...int middle=0;
otherwise a[middle] is taking some arbitary position as there is no bound checking |
Re: C++ assignment
You've forgotten C counts from zero. The code looks at a[11], which doesn't exist (27.3 is a[10]), and completely ignores a[0].
I don't see the point of "i". Why not just use while(a[middle]!=item)? Also the code doesn't call a function as required by the task notes. It does everything in main(). |
Re: C++ assignment
Hello....in my computer the binary search is running absolutely perfect.....here, have a look at my algorithm.....
Code:
#include<stdio.h>--------------- @ r K @ |
Re: C++ assignment
You can also run it using
Code:
int n;Code:
float n;---------------- @ r k @ |
| All times are GMT +5.5. The time now is 19:44. |