+ 1
[SOLVED] Can I find the top value between three variables by while? ?and how?
7 odpowiedzi
+ 23
for 3 numbers
https://code.sololearn.com/cguktJlM37R1/?ref=app
this one for n numbers👇
https://code.sololearn.com/cNH72y47v3Vq/?ref=app
+ 21
https://code.sololearn.com/c77NTyoxKFVD/?ref=app
Is this what you wanted ?
+ 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
+ 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
+ 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;
0
useing while please
0
thanks