+ 1

[SOLVED] Can I find the top value between three variables by while? ?and how?

3rd May 2018, 7:51 PM
A M
A M - avatar
7 odpowiedzi
3rd May 2018, 8:04 PM
AliR૯za
AliR૯za - avatar
+ 21
https://code.sololearn.com/c77NTyoxKFVD/?ref=app Is this what you wanted ?
3rd May 2018, 8:09 PM
AliR૯za
AliR૯za - avatar
+ 1
if you mean the maximum between 3 values there's a few ways to do that 1. use a for loop, assign the current value to a variable, then use if's to check if the next value is bigger 2. max(max(a, b), c) 3. load them into an array, iirc there is a max function for arrays
3rd May 2018, 8:04 PM
hinanawi
hinanawi - avatar
+ 1
assume there are 3 ints, a, b, c int max = a; while (max < b) max = b; while (max < c) max = c; so max is what you want
3rd May 2018, 8:04 PM
🇮🇷 M N
+ 1
It's not the most efficient method: int a = 4; int b = 42; int c = 13; int *ptrs[3] = {&a, &b, &c}; int x = 0; int ii = -1; while (++ii < 3) if (x < *(ptrs[ii])) x = *(ptrs[ii]); Do you have to use while()? Short-hand ifs are better: x = (x < a) ? a : x; x = (x < b) ? b : x; x = (x < c) ? c : x;
3rd May 2018, 11:28 PM
non
0
useing while please
3rd May 2018, 8:07 PM
A M
A M - avatar
0
thanks
3rd May 2018, 8:18 PM
A M
A M - avatar