Question

Im using visual studio to write a c++ program has a function that will output the...

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);
}

Homework Answers

Answer #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);
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std;...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std; int main() {        int x;        cout << "Selection option " << endl;        cin >> x;        if (x == 1)               cout << "You select option 1" << endl;        else if (x >= 2 || x <= 4)               cout << "You select options 2 or 3 or 4" << endl;               else if (x == 10)               cout << "You select option 10" << endl;               else...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int fib(int n) { int temp; if (n <= 0)    return 0; else if (n <= 2)    return 1; else {    temp = fib(n – 1);    return temp + fib(n-2); } } int main() {    int num;    cout << "Which fibonacci number? ";    cin >> num;    cout << fib(num) << endl;    return 0; } You...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream>...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream> using namespace std; void shownumbers(int, int); int main() { int x, y; cout << "Enter first number : "; cin >> x; cout << "Enter second number : "; cin >> y; shownumbers(x, y); return 0; } void shownumbers(int a, int b) { bool flag; for (int i = a + 1; i <= b; i++) { flag = false; for (int j =...
Analyze the following programs and write down the output of the program. Please print every character...
Analyze the following programs and write down the output of the program. Please print every character (including whitespace character) clearly!       # include <iostream> using namespace std;   int fun( int a ) {       int b = a * 2;       return b;   }   int main()   {       int y = 5;       cout << fun(y) << endl;       cout << fun(-- y) << endl;       cout << fun(y--) << endl;       cout << y <<endl;           return 0;   }
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
im trying to make a program that will use a while loop to repeatedly ask a...
im trying to make a program that will use a while loop to repeatedly ask a user for a test score. Use a counter to exit the loop when the user has entered 10 test scores. The loop is to figure out the total of all the scores and the highest score. it must use a while loop please explain problems in code the bottom code is my work done but does not work. #include <iostream> using namespace std; int...
Below is my C++ program. There is a function to add data, display it and search...
Below is my C++ program. There is a function to add data, display it and search the data. Just add two more functions to this porgram. One function to update the student data and second function to delete the data. Also, change the display function little bit. Right now, it shows all data entered. Make it so you have to put the uin number and it only displays the data of that specific student. #include <iostream> #include <string> using namespace...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include <cmath> using namespace std; int getWeight(); float deliveryCharge(int weight); void displayCharge(int weight); int main () {    displayCharge(getWeight());    return 0; }   int getWeight() {    int weight;    cout << "Enter package weight (oz): ";    cin >> weight;    return weight; } float deliveryCharge(int weight) {    if (weight > 16)    {        return (((weight - 16) / 4) *...
The program runs but the math is not correct ( output for amount ) #include <iostream>...
The program runs but the math is not correct ( output for amount ) #include <iostream> using namespace std; int main() { int hoursParked; double total; double Car = 2.50 ; double Truck = 5.50; double Bus = 19.00; double rateC = 1.50; double rateT = 3.75; double rateB = 6.75; char type; cout << "Please Enter number of hours parked and the type of car (Type: (C)ar or (T)ruck or (B)us): " << endl; cin >> type >> hoursParked;...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT