Question
Please help asap
Q6

6 (15%) Fill up the missing bodies of factorialO and fibonacciO of the following codes: #include <iostream> using namespace std; unsigned long factorial(unsigned long); unsigned long fibonacci(unsigned long); / / function prototype int main0 unsigned long size_factorial, size fibonacci; cout << input an unsigned integer for the upper bound of factorialO < endl; cin >> size factorial; cout << input an unsigned integer for the upper bound of fibonacci) <endl; cin >>size_fibonacci; cout << the result of factorial( size factorial) ia:< factorial(size_factorial) << endl; cout << the result of fibonacci( size_fibonacci) ia: << fibonacci(size_fibonacci) << endl; cout<the sum of factorial(size_factorial) and fibonacci(size_fibonacci) is << factorial(size factorial) + fibonacci(size fibonacci) <<endl; 3 // end main unsigned long factorial(unsigned long number)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

using namespace std;

unsigned long factorial( unsigned long );

unsigned long fibonacci(unsigned long );

int main(){

unsigned long size_factorial,size_fibonacci,result;

cout<<"input an unsigned integer for thr upper bound of factorial() "<<endl;

cin>>size_factorial;

cout<<"input an unsigned integer for thr upper bound of fibonacci() "<<endl;

cin>>size_fibonacci;

cout<<"the result of factorial(size_factorial) is: "<<factorial(size_factorial)<<endl;

cout<<"the result of fibonacci(size_fibonacci) is: "<<fibonacci(size_fibonacci)<<endl;

cout<<"the sum of factorial(size_factorial) and fibonacci(size_fibonacci) is ";

result=factorial(size_factorial)+fibonacci(size_fibonacci);

printf("%lu",result);

return 0;

}

unsigned long factorial( unsigned long number ) {

if ( number <= 1 ) { return 1 ; }

else {

return ( number * factorial( number - 1 ) );

}

}

unsigned long fibonacci(unsigned long number){

unsigned long a=0,b=1,c=1;

if(number==0){

return a;

}

for(unsigned long i=1;i<=number;i++){

c=a+b;

a=b;

b=c;

}

return b;

}

oaS actoraro and lioonaccio of the tollowing codes #include <iostream> using namespace std Flallfactfib.exe input an unsigned

Add a comment
Know the answer?
Add Answer to:
Please help asap Q6 6" (15%) Fill up the missing bodies of factorialO and fibonacciO of...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help coding this program and please explain how the operations work in pseudocode please. Problem:...

    Need help coding this program and please explain how the operations work in pseudocode please. Problem: Starting with the following C++ program #include <iostream> using namespace std; void main () long Var16; long Var210; long var3 = 15; long Var4 21; long Var522; long Sum; long Result; long Remainder; const unsigned byte c-6: const unsigned byte c2-10; const unsigned byte c3-15 const unsigned byte c4 21; const unsigned byte c5 22; a sm cout << "Sum is cout << "Result...

  • This is a fill in the code type: // FILL IN THE CODE - Write a...

    This is a fill in the code type: // FILL IN THE CODE - Write a program to multiply 2 numbers, print out the results and print out the original numbers in ascending order. #include <iostream> using namespace std; int main() {   int num1;       // holds 1st number   int num2;       // holds 2nd number   int result;       // holds result of multiplication   int *num1Ptr = nullptr; // int pointer which will be set to point to the 1st number   int *num2Ptr...

  • Who could write the array.cpp file ?   //main.cpp #include "array.hpp" #include <iostream> int main() { int...

    Who could write the array.cpp file ?   //main.cpp #include "array.hpp" #include <iostream> int main() { int n; std::cin >> n; array a(n); for (int i = 0; i < n; i++) { std::cin >> a.data()[i]; } std::cout << "array size:" << a.max_size() << std::endl; std::cout << "array front:" << a.front() << std::endl; std::cout << "array back:" << a.back() << std::endl; int* data = a.data(); std::cout << "array elements using data:" << std::endl; for (int i = 0; i < n;...

  • Having to repost this as the last answer wasn't functional. Please help In the following program...

    Having to repost this as the last answer wasn't functional. Please help In the following program written in C++, I am having an issue that I cannot get the reducdedForm function in the Rational.cpp file to work. I cant figure out how to get this to work correctly, so the program will take what a user enters for fractions, and does the appropriate arithmetic to the two fractions and simplifies the answer. Rational.h class Rational { private: int num; int...

  • I am having trouble figuring out why my program will not make any columns, just rows....

    I am having trouble figuring out why my program will not make any columns, just rows. I need to display a square. The instructions are provided below. (This for my C++ class) Write a program that displays a square. Ask the user for the square’s size. Only accept positive integer numbers (meaning choose a data type that holds positive integer values). The size the user gives you will determine the length and width of the square. The program should then...

  • c++ Some pieces of the following code are missing. Fill in the blanks of the following...

    c++ Some pieces of the following code are missing. Fill in the blanks of the following program. Each answer must fit on a single line. include <iostream> #include <cstdib #include <ctimes using namespace std; randoml_event return 2 (rand() 5 random2 intre + rand 90 return ret: random1_1000X rand) intret 100 return ret: fint 2) return nt; return n2 is oder Is_odot if (n%2 0) return return true; int sum3 (int n, int n, int n3 X int sum= n1 +...

  • If your initial bet was $5, your second bet must be $10, then $15, etc. If...

    If your initial bet was $5, your second bet must be $10, then $15, etc. If your initial bet was $2, your second bet must be $4, then $6, etc. Write a program that outputs the sum of the first "numBets" multiples of a number "initialBet", where "numBets" and "initialBet" are integers taken in as user input. #include <iostream> using namespace std; int main() {    cout << "Enter the initial bet, followed by "         << "the number of...

  • I am using C++ Start with the distance.cpp file on the website. Fill in the missing...

    I am using C++ Start with the distance.cpp file on the website. Fill in the missing functions to enable the program to compile and correctly find determine which entered distance is larger. The user can either enter it in meters labeled with an “m”, or in feet and inches labeled with and ' and “. You may not change main(), we will check to ensure it is exactly the same. The meters and inches can be doubles, but the feet...

  • Finish the following program which adds up all integers from 0 to the user's given number inclusively using a While Loop

    // Finish the following program which adds up all integers from 0 to// the user's given number inclusively using a While Loop. The total should be// assigned to the variable 'total'.#includeusing namespace std;int main() {int number;int total = 0;int counter = 0; //initialize the variable// user enters a numbercout << "Enter a positive integer to find the summation of ";cout << "all numbers from 0 to the given number up to 100." << endl;cin >> number;// check for invalid user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT