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 fibonacci(int n) { if (n <= 1) { return n; } else { return fibonacci(n - 1) + fibonacci(n - 2); } } int waysToClimb(int numStairs) { return 1 + fibonacci(numStairs); } int main() { int n; cout << "How many stairs: "; cin >> n; cout << "Fibonacci of " << n << " is " << fibonacci(n) << endl; cout << "Number of ways to climb staircase is " << waysToClimb(n) << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.