|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
curiousEngine wrote:
> if (A > B){ > if (A > C) > max = A; > } else { > if (B > C) > max = B; > else if (C > A) > max = C; > } If you want to do your homework in a bit more obfuscated way, you can do that with a one-liner: max = A > B ? A > C ? A : C : B > C ? B : C; |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Oct 15, 1:01 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
[snip] > If you want to do your homework in a bit more obfuscated way, you can > do that with a one-liner: > > max = A > B ? A > C ? A : C : B > C ? B : C; I compiled this, with appropriate int main etc. added to make a complete program. It printed out the words to Aida. Socks |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Puppet_Sock wrote:
> On Oct 15, 1:01 pm, Juha Nieminen <nos...@thanks.invalid> wrote: > [snip] >> If you want to do your homework in a bit more obfuscated way, you can >> do that with a one-liner: >> >> max = A > B ? A > C ? A : C : B > C ? B : C; > > I compiled this, with appropriate int main etc. > added to make a complete program. It printed out > the words to Aida. Are you trying to imply that the standard doesn't define precedence rules for nested ?: operators? I suppose you could make it more unambiguous by using clarifying parentheses, like: max = A > B ? (A > C ? A : C) : (B > C ? B : C); However, are they really necessary (except for the human reader)? |
|
![]() |
| Outils de la discussion | |
|
|