求教帮我看看一个程序
用for循环语句编程求1!+2!+…+20! 程序提示:
定义int型变量sum,p
赋初始值p=1;sum=0;
输入n的值
for (i=1;i<=20,i++)
{
p=p*i;
sum=sum+p;
}
输出sum
是这样写的吗?
#include<stdio.h>
int mian()
{
int sum,p;
p=1,sum=0;
for(i=1;i<=20,i++)
{
p=p*i;
sum=sum+p;
}
return=0
}
#include <stdio.h> #include <stdint.h> #include <inttypes.h> int main() { const unsigned n = 20; uint64_t sum = 0; uint64_t f = 1; for( unsigned i=1; i!=n+1; ++i ) { f *= i; sum += f; } printf( "%"PRIu64"\n", sum ); // 2561327494111820313 return 0; }