programming challenge (silly)

pathak at s.cs.uiuc.edu pathak at s.cs.uiuc.edu
Sat Mar 11 12:44:00 AEST 1989



In an article by kjell at saturn.ucsc.edu writes

>I have 91 now but am not sure about portability of main(n,m) and printf.
>
>main(n,m){scanf("%d\n",&m);while(m>1&m<10)n*=m--;
>printf(m-1?"error\n":"answer is %d\n",n);}

Well, the code I ran the code through wc and it came out to be 92 chars.
Still, it is a nice piece of code.  However, the following modifications make
the same code only 89 chars.



main(n,m){for(scanf("%d",&m);m>1&m<10;n*=m--);
printf(m-1?"error\n":"answer is %d\n",n);}

Of course, you need to delete the newline after the first line.  The code 
could further be optimized by getting rid of the extra "\n" after error and 
answer which would make it 85.


Heeren Pathak
s.cs.uiuc.edu
zaphod.ncsa.uiuc.edu



More information about the Comp.lang.c mailing list