【问题】n!怎么写 要求用#define N 100 精确到每一位
RT提示:用数组。
我是实在想不出 网上的资料也没看懂.
程序代码:#include <stdio.h>
void foo( unsigned n )
{
unsigned char buf[200] = { 1, 0 };
unsigned buflen = 1;
for( unsigned i=2; i<=n; ++i )
{
unsigned c = 0;
for( unsigned j=0; j<buflen; ++j )
{
c += i*buf[j];
buf[j] = c%10;
c /= 10;
}
for( unsigned j=buflen; c!=0; ++j )
{
buf[j] = c%10;
c /= 10;
++buflen;
}
}
printf( "%d! = ", n );
for( unsigned i=buflen; i!=0; --i )
printf( "%d", buf[i-1] );
printf( "\n" );
}
int main()
{
foo( 1 );
foo( 2 );
foo( 3 );
foo( 25 );
foo( 100 );
return 0;
}