Path: utzoo!attcan!uunet!ingr!crossgl From: crossgl@ingr.com (Gordon Cross) Newsgroups: comp.lang.c Subject: Re: programming challenge (silly) Message-ID: <4340@ingr.com> Date: 9 Mar 89 21:24:13 GMT References: <2102@jasper.UUCP> Reply-To: crossgl@ingr.UUCP (Gordon Cross) Distribution: na Organization: Intergraph Corp. Huntsville, Al Lines: 32 In article <2102@jasper.UUCP> c415-23@alberta.UUCP (Morris Barbara L) writes: %A friend and I tried to mimic the behaviour of the following program in %the fewest characters possible. The best we were able to do was 98 %characters (result of wc). Can anyone beat this? Email for our solution. % %main() %{ % int n; % % scanf( "%d", &n ); % if ( n < 1 || n >= 10 ) % printf( "error\n" ); % else printf( "answer is %d\n", factorial( n ) ); %} % %int factorial( n ) %int n; %{ % if ( n == 1 ) % return( n ); % else return( n * factorial( n - 1 ) ); %} OK, how about 94 characters (line split here so you can see it better): n,v;main(){scanf("%d",&n);for(v=n>0&n<10;v&&n;v*=n--); printf(v?"answer is %d\n":"error\n",v);} -- Gordon Cross UUCP: uunet!ingr!crossgl "all opinions are 111 Westminister Way INTERNET: crossgl@ingr.com mine and not those Madison, AL 35758 MA BELL: (205) 772-7842 of my employer."