programming challenge (silly)
Gordon Cross
crossgl at ingr.com
Fri Mar 10 07:24:13 AEST 1989
In article <2102 at jasper.UUCP> c415-23 at 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 at ingr.com mine and not those
Madison, AL 35758 MA BELL: (205) 772-7842 of my employer."
More information about the Comp.lang.c
mailing list