Liste des Groupes | Revenir à cl c |
Tim ruled out &&, ||, ?:, goto, break, continue, if, for, while, switch, do, labels, setjmp and longjmp.Isn't this just !n ? I don't think "!" was ruled out. This would also work for negative n.
He didn't rule out recursion, or the relational operators, or any other part of C.
int fact(int n);
int fact_zero(int n) {
return 1;
}
int n_fact_n1(int n) {
return n * fact(n - 1);
}
int fact(int n) {
return (int (*[])(int)){ fact_zero, n_fact_n1 }[(bool) n](n);
}
There are additional fun things that can be done using different operators. For an unsigned integer "n" that is not big enough to wrap, "(n + 2) / (n + 1) - 1" evaluates "(n == 0)".
And Tim did not rule out using the standard library, which would surely open up new possibilities.printf (not sprintf) would be reasonable here to show results. Anything else could be considered cheating.
Les messages affichés proviennent d'usenet.