#include <iostream> #include <cassert> using namespace std;
double add(double); double fibonacci(double);
int main() { double n; bool t=true; while(t) { t=false; cout << "Please input a integer " << endl; cin >> n; assert(n<=1000); assert(n>=0); cout << endl << "1+2+3+..............+" << n << "=" << add(n) << endl; cout << "If you want to rerun around or run a other one,please input 1 " << endl; cin >> t; }
t=true; while(t) { t=false;getchar(); cout << "Please input a integer" << endl; cin >> n; assert ( n<=50 ); assert ( n>=0 ); cout << "The " << n <<"th's faibonacci is " << fibonacci( n ) <<endl; cout << "If you want to rerun around or run a other one,please input 1 " << endl; cin >> t; } return 0; }
double add(double n) { if (n>0) return n+add(n-1); else return n; }
double fibonacci( double n ) { if ( n==1 ) return 1; if ( n==2 ) return 1; return fibonacci( n-1 ) + fibonacci( n-2 ); }