You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

26 lines
360 B

//6.1.test.cpp
#include <iostream>
using namespace std;
int fact(int x);//如果函数出现在调用之后,需要声明
int main(){
cout << "请输入一个数,将计算它的阶乘" << endl;
int x;
cin >> x;
cout << "阶乘为:";
cout << fact(x) << endl;
return 0;
}
int fact(int x){
int i,j;
for(i=1;i<=x;i++){
j =i*j;
}
return j;
}