cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Comparing four number for min
Comparing four number for min
Sep 17, 2016 at 8:55pm UTC
HG319
(98)
I have four numbers and I need to find the min, but the min cannot be zero. What would be a simple algorithm for that?
I originally used the std:min() but then I realized if
1
2
3
4
5
6
x=0; y=1; z=2; t=6; min(x,y) min(z,t)
I won't get the min I actually need. I also have to keep in mind that more than one variable can be 0
Sep 17, 2016 at 9:31pm UTC
Arslan7041
(753)
Set min to be the first variable. Then check if second variable is less than min; if it is, make that the new min. Repeat for third and fourth variable.
Last edited on
Sep 17, 2016 at 9:32pm UTC
Sep 17, 2016 at 9:43pm UTC
HG319
(98)
if there is a zero that does not work. My min can't be zero
Last edited on
Sep 17, 2016 at 9:43pm UTC
Sep 17, 2016 at 10:29pm UTC
SamuelAdams
(1535)
The check each value to make sure it's larger than 0.
Topic archived. No new replies allowed.