@chawuciren
2018-12-03T15:10:37.000000Z
字数 648
阅读 702
C++
这个放在头文件
head.h
int Factorial(int);
int fun2();
int fun3(int n);
以下放在源文件
file1.cpp
#include<iostream>
using namespace std;
#include"head.h"
int Factorial(int n){
if (n == 1)
return 1;
else return n * Factorial(n - 1);
}
file2.cpp
#include<iostream>
using namespace std;
#include"head.h"
int fun2(){
int res = 0;
res = (Factorial(5) + Factorial(7)) / 8;
return res;
}
file3.cpp
#include<iostream>
using namespace std;
#include"head.h"
int fun3(int n){
int res=0;
for (int i = 1; i <= n; i++){
res += Factorial(i);
}
return res;
}
mainf.cpp
#include<iostream>
using namespace std;
#include"head.h"
int main(){
int n1 = fun2();
cout <<"5!+7!的和除8的结果是:"<< n1 << endl;
int n2 = fun3(10);
cout <<"1-10的阶乘的和是:"<< n2 << endl;
system("pause");
return 0;
}
然后运行就好了