Collatz sequence in C++
Calculate Collatz (3n + 1) sequence in C++ problem You wish to print the infamous Collatz sequence also known as 3n + 1. Given a natural number greater than 0, if it’s odd you multiply by 3 and add 1, otherwise you divide it by 2 and repeat this process until it becomes 1. Fun […]
Calculate Fibonacci number in C++
Calculate Fibonacci number in C++ problem You would like to calculate the nth Fibonacci number using the C++ programming language. Recall that the sequence of Fibonacci as follows: SOLUTION Let’s use recursion as the mathematical problem has a recursive nature. The function prototype will look as follow: long int fibonacci(int fth); The implementation of it […]