0
Even and odd
How to get the minimum for only even number and the maximum to only maximum?
11 Answers
+ 2
Is there any restriction? like prohibition of standard library support?
+ 2
No, I mean, are you allowed to use functions from <algorithm>? or are you supposed to write your own?
+ 2
At start you search for the first even number and save its value to min.
Then the same for odd number.
After that you search which of them are smaller repectively greater and print the result.
+ 2
JOKER
And this is the implementation of my above mentioned algorithmus:
https://code.sololearn.com/cayHETL6q2Y3/?ref=app
+ 1
Ok, well, you would need 2 variables e.g. <min_even> and <max_odd>. Assign value of the first array element to both of them.
Then you setup a for-loop, going from index 1 (second element) going forward up to the last element.
Inside the loop:
Check whether array[i] was even/odd.
* If it is even, compare with <min_even> and update <min_even> when array[i] is less than <min_even>.
* If it is odd, compare with <max_odd> and update <max_odd> when array[i] is greater than <max_odd>.
(Edit)
You can also read the array from both ends if the array was already, or allowed to be sorted.
+ 1
ok thanks alot
0
In an array? or from direct input with a sentinel?
0
array
0
iostream library
0
#include<iostream> and I am not allowed to use any thing except of the basic things
0
nope I am supposed to write my own