On 5 Aug 2006 10:58:44 -0700 in comp.lang.c++, "Podrzut_z_Laweczki"
on how to make it 2 x shorter (it takes last digit from n!) just a hint
#include <cstdio>
int main(){int
c;scanf("%d",&c);printf("%d\n",c?c==3?6:c==1||c==2||c==4?c:0:1);}
It's not clear to me from your question exactly how you want to
improve your code. The code suffers severely from having too much
stuff crammed together without spacing (unless that is just
something your newsreader did to you.) The first major step toward
improving it is to space things out with standard indentation.
After that, replace the convoluted conditional expression with "if"
statements that can also be indented to clarify the structure.
Having done that, you will notice a nested "if" inside the first
"if". Reverse the condition to transform that into a chained "else
if" structure.
Bad:
if ()
if()
if()
Good:
if()
else if()
else if()
From there, the code should be comprehensible enough to make clear
the way to the modifications you wanted.
As follows:
#include <cstdio>
int main()
{
int c;
scanf("%d", &c);
int result;
if (c == 0)
result = 1;
else if (c == 3)
result = 6;
else if (c == 1 || c == 2 || c == 4)
result = c;
else
result = 0;
printf("%d\n", result);
}
If I have made any mistake in the above transformation, blame it on
the horribly convoluted styling of the original -- but recheck it
yourself before trusting it.
Finally, it appears at this point that a simple table lookup may be
a more straightforward approach to your problem. Remember, the
*first goal* is to write code that is plainly and clearly correct!