searches an array[50]

Write your question here.
Hallo guys
i have a problem with a question. "Impelment in a program in C++ which searches an array (for example double arr[50];) for all values which are greater than a particular number (for example a=50;) and prints these numbers on the screen.

What i did is the following

1
2
3
4
5
double arr[50]={};
int i;
for (i=0; i=50; i++)
{std::cout<<"insert",,i,,"elemenent"<<std::endl;
std::cin>>arr[i];}
Have you learned about linear search or binary search?
The link could help you on how to write the code.
http://www.cplusplus.com/forum/general/75624/

Pseudocode for linear search.
Set found to false.
Set position to −1.
Set index to 0.
While found is false and index < number of elements
If list[index] is equal to search value
found = true.
position = index.
End If
Add 1 to index.
End While.
Return position.

Here is the pseudocode for a function that performs a binary search on an array:
Set first index to 0.
Set last index to the last subscript in the array.
Set found to false.
Set position to −1.
While found is not true and first is less than or equal to last
Set middle to the subscript halfway between array[first]
and array[last].
If array[middle] equals the desired value
Set found to true.
Set position to middle.
Else If array[middle] is greater than the desired value
Set last to middle − 1.
Else
Set first to middle + 1.
End If.
End While.
Return position.
Topic archived. No new replies allowed.