题目3:爬楼梯

#include "stdafx.h"
#include<iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
int n=0;
int result;
cout<<"plase input to top's step number(n):";
cin>>n;cout<<endl;

cout<<"output all different way:";
int climbStairs(int n);
result= climbStairs(n);
cout<<result<<endl;
return 0;
}

int climbStairs(int n)
{


int result = 1, begin= 1, next = 1;
while (--n > 0)
{
result = begin + next;
begin = next;
next = result;
}

return result;
}

原文地址:https://www.cnblogs.com/RealQ/p/6517202.html