Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ucbarpa.Berkeley.EDU!klier From: klier@ucbarpa.Berkeley.EDU (Pete Klier) Newsgroups: comp.lang.c Subject: Re: programming puzzle (silly) Summary: 88 char portable solution Message-ID: <28336@ucbvax.BERKELEY.EDU> Date: 10 Mar 89 02:04:48 GMT Sender: usenet@ucbvax.BERKELEY.EDU Lines: 17 *********************** main(m,n){scanf("%d",&n);for(m=n>0^n>9;n&&m*=n--;); printf(m?"Answer=%d\n":"error\n",m);} *********************** with help from Jeff Conroy (jmconroy@ernie.Berkeley.EDU) the expression "m=n>0^n>9" is equivalent to "m = (n > 0) && (n <= 9)" (check it out) so "m" is 1 (initially) iff n is within range, 0 otherwise. If m is 0 in the body of the loop, then the expression (n&&m*=n--) is 0, since (m*=n--) is 0. Otherwise, we have an ordinary factorial loop, which begins with m == 1. Pete Klier klier@ernie.Berkeley.EDU