Reference no: EM132164462
Using C++
Do not make use of any variables in your answers to this question.
Only consider positive numbers.
Part A. Write a function parta(int x) which prints a sequence of numbers starting with x itself, and counting down, but stopping after it first prints a number that is divisible by 11. For example, parta(30) should print:
30 29 28 27 26 25 24 23 22
Part B. Write another function partb(int x) which does not print anything, but instead returns as its result the length of the sequence that parta(x) would have printed.
For example, const int n = partb(30) should set n to 9, because parta(30) prints 9 numbers.
Part C. There is a mysterious mathematical thing called a Collatz Sequence. It can start with any number N. If N is odd, the rest of the sequence is the collatz sequence starting from 3*N+1, but if N is even, the rest of the sequence is the collatz sequence starting from N/2. The sequence stops after it reaches 1.
Write a function partc(int N) which prints the entire Collatz sequence starting from N.
For example, partc(24) should print:
24 12 6 3 10 5 16 8 4 2 1
Part D. Write another function partd(int N) which returns as its result the length of the Collatz sequence that starts with N.
For example, partd(24) is equal to 11, because as you can see from the previous example, the Collatz sequence starting from 24 consists of 11 numbers.