|
我现在想认真学习C语言!我刚刚起步,不免有些很笨的问题,谢谢兄弟们的指教!
这是关于对阶乘求和的问题,题目是:
求1!+2!+3!+4!+5!+6!+7!+8!+9!.......+17!+18!+19!+20!
我写的代码是:
[code:1]main()
{
int i,sum;
for(i=1,sum=0;i<=20;sum+=jiecheng(i),i++)
printf("%ld",sum);
}
int jiecheng (int n)
{
long a;
int n;
while(n<=20&&n>=1)
{a=20;n--;a*=(n-1);}
return(a);
}[/code:1]
编译凑合着通过了,但是运行后吓了我一跳!请看:
[code:1]@fydream yuandaima]$ gcc -o fy 64.c
64.c: In function `jiecheng':
64.c:10: warning: declaration of `n' shadows a parameter
64.c:14:2: warning: no newline at end of file
[fydream@fydream yuandaima]$ ./fy
05181436103628721554430820725744259071803108861636270052414514884663292451814360569957966217723267358668725401047772154082902976880844129326584898447284[fydream@fydream yuandaima]$
[/code:1]
谢谢兄弟们的帮助! |
|