您的位置首页百科问答

c语言求阶乘的和

c语言求阶乘的和

1 #include 2 int main() 3 { 4 int i=0; 5 long temp=1; 6 long sum=0; 7 for(i=1;i<=20;i++) 8 { 9 temp*=i; 10 sum+=temp; 11 } 12 printf("sum=%ld\n",sum); 13 return 0; 14 } ___________________ cl之后,执行: ____________________ Microsoft (R) 32-bit C/宽兄C++ Optimizing Compiler Version 12.00.8168 for 80x86 Copyright (C) Microsoft Corp 1984-1998. All rights reserved. baidu.c Microsoft (R) Incremental Linker Version 6.00.8168 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. /out:baidu.exe baidu.obj sum=268040729 请按 ENTER 或其它命令继续_________________to 楼上:你的for里边的sum1每次重新消陵从1开慎桥袭始算,很浪费的,直接用上一次的结果就行.