uibk_703602-Compiler-Constr.../examples/binary_search/binary_search.mc
2019-01-06 12:11:47 +01:00

48 lines
595 B
MonkeyC

bool binary_search(int[20] arr, int val)
{
int i;
i = 0;
while(i < 20)
{
if(arr[i] == val)
{
return true;
}
i = i + 1;
}
return false;
}
int main()
{
int[20] arr;
int i;
i = 0;
while(i < 20)
{
arr[i] = i;
i = i+1;
}
print("Please enter a number to search for: ");
int n;
n = read_int();
print_nl();
if (binary_search(arr,n)) {
print("Value was found!");
}
else {
print("Value was not found!");
}
print_nl();
return 0;
}