-
红颜莎娜
12345678910111213141516171819#include <stdio.h> int foo(int n){ int i, r = 1; for (i = 1; i <= n; i++) r *= i; return r;} int main(void){ int sum = 0; int i; for (i = 1; i < 10; i++) sum += foo(i); printf("%d\n", sum); return 0;}
-
长风秋雁
#include<stdio.h>int fac(int a){if(a==1)return 1;elsereturn fac(a-1)*a;}main(){int b,sum=0;printf("请输入你想输入的数字:\n");scanf("%d",&b);for(int i=1;i<b+1;i++)sum=sum+fac(i);printf("%d\n",sum);}下面是C++的程序(输入的时候输入10):#include<iostream.h>int fac(int a){if(a==1)return 1;elsereturn fac(a-1)*a;}main(){int b,sum=0;cout<<"请输入你想输入的数字:"<<endl;cin>>b;for(int i=1;i<b+1;i++)sum=sum+fac(i);cout<<sum<<endl;}科班出身,程序完全正确~!
-
智慧大石
#include<iostream>using namespace std;int main(){int sum = 0;int t = 1;for(int i = 1; i <= 10; i++){t *= i;sum += t;}cout<<"sum="<<sum<<endl;return 0;}结果是sum=4037913Press any key to continue我用的软件是visual C++ 6.0的
-
海绵宝宝撒
#include<iostream.h>void main(){int s=0,i,t=1;for(i=1;i<=10;i++){t=t*i;s=s+t;}cout<<"1到10的阶乘之和为:"<<s<<endl;}