1.求一个数的阶乘n!:
#include<iostream>
using namespace std;
int fac(int val);
int main(){
int val;
cout<<"input a number:"<<endl;
cin>>val;
cout<<"val! is "<<fac(val)<<endl;
}
int fac(int val){
if(val==1||val==0)
return 1;
else if(val<0){
cout<<"input error!"<<endl;
}
return val*fac(val-1);
}
2.Fibonacci数列(斐波那契数列)
1,1,2,