Im using visual studio to write a c++ program has a function that will output the number if ways a person can climb stairs using only 1 or two steps and and function that when given a number outputs the corresponding fibonacci number. I want to call the functions in main.
#include <iostream>
using namespace std;
int FiboNum(int fiboNum);
int Stairs(int nStairs);
int main()
{
int fiboNum;
int nStairs;
cout << "Enter a number : " << endl;
cin >> fiboNum;
cout<<FiboNum(fiboNum);
getchar();
cout << "Enter number of stairs : " <<
endl;
cin >> nStairs;
cout<<Stairs(nStairs);
system("pause");
return 0;
}
int FiboNum(int fiboNum)
{
if (fiboNum <= 1)
return fiboNum;
return FiboNum(fiboNum - 1) + FiboNum(fiboNum);
}
int Stairs(int nStairs)
{
int stair = nStairs;
if (nStairs == 1 || nStairs == 0)
return 1;
else if (nStairs == 2)
return 2;
else
return Stairs(nStairs - 3) +
Stairs(nStairs - 2) + Stairs(nStairs - 1);
}
#include <iostream> using namespace std; int FiboNum(int fiboNum); int Stairs(int nStairs); int main() { int fiboNum; int nStairs; cout << "Enter a number : " << endl; cin >> fiboNum; cout << FiboNum(fiboNum); getchar(); cout << "Enter number of stairs : " << endl; cin >> nStairs; cout << Stairs(nStairs); system("pause"); return 0; } int FiboNum(int fiboNum) { if (fiboNum <= 1) return fiboNum; return FiboNum(fiboNum - 1) + FiboNum(fiboNum - 2); } int Stairs(int nStairs) { return 1 + FiboNum(nStairs); }
Get Answers For Free
Most questions answered within 1 hours.