本来想添加一个输入是否为数字的判断,没成功,以后再改进!
- #include <iostream>
-
-
using namespace std;
-
-
double f1( double a, double b=1){
-
b*=a;
-
if(a==1) return b;
-
else f1(a-1,b);
-
}
-
-
void f2(int& c){
-
double a,b;
-
cout << "Enter the number: ";
-
cin >> a;
-
b=f1(a);
-
cout << a << "!= "<< b <<endl;
-
cout <<'\n';
-
}
-
-
int main (){
-
int a(1);
-
while(a==1){
-
f2(p);
-
cout<<"Do you want to do another calculation? y/n \n";
-
char str;
-
cin>>str;
-
if(str=='Y'||str=='y')continue;
-
if(str=='N'||str=='n')a=0;
-
}
-
return 0;
-
-
}