- #include <iostream>
- using namespace std;
- int main()
- {
- int fac(int);
- int judge(int );
- int b,c,d;
- long e,f,g,sum;
- cout<<"请输入三个数,计算机将为您计算它们的阶乘并求和"<<'\\n';
- cin>>b;
- judge(b);
- e=fac(b);
- cin>>c;
- judge(c);
- f=fac(c);
- cin>>d;
- judge(d);
- g=fac(d);
- sum=e+f+g;
- cout<<"sum="<<sum<<'\\n';
- return 0;
- }
- int fac(int j)
- {
- long carrot=1;
- for(int i=1;i<=j;i++)
- {
- carrot=carrot*i;
- }
- return carrot;
- }
- int judge(int k)
- {
- while(k<0)
- {
- cout<<"404,请重新输入"<<'\\n';
- cin>>k;
- }
- while(k==0)
- {
- k=1;
- }
- return k;
- }
- //该片段来自于http://www.codesnippet.cn/detail/140320149045.html
来源: http://www.codesnippet.cn/detail/140320149045.html