0

Even and odd

How to get the minimum for only even number and the maximum to only maximum?

12th Feb 2021, 3:53 PM
JOKER
11 Answers
+ 2
Is there any restriction? like prohibition of standard library support?
12th Feb 2021, 4:03 PM
Ipang
+ 2
No, I mean, are you allowed to use functions from <algorithm>? or are you supposed to write your own?
12th Feb 2021, 4:05 PM
Ipang
+ 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.
12th Feb 2021, 6:03 PM
JaScript
JaScript - avatar
+ 2
JOKER And this is the implementation of my above mentioned algorithmus: https://code.sololearn.com/cayHETL6q2Y3/?ref=app
12th Feb 2021, 6:09 PM
JaScript
JaScript - avatar
+ 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.
12th Feb 2021, 4:17 PM
Ipang
+ 1
ok thanks alot
12th Feb 2021, 4:18 PM
JOKER
0
In an array? or from direct input with a sentinel?
12th Feb 2021, 3:58 PM
Ipang
0
array
12th Feb 2021, 3:58 PM
JOKER
0
iostream library
12th Feb 2021, 4:03 PM
JOKER
0
#include<iostream> and I am not allowed to use any thing except of the basic things
12th Feb 2021, 4:04 PM
JOKER
0
nope I am supposed to write my own
12th Feb 2021, 4:06 PM
JOKER