Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement the following function using recursion. Do not use any local variables

ID: 666691 • Letter: I

Question

Implement the following function using recursion. Do not use any local variables or loops.

  
void pattern(unsigned int n)

   // Precondition: n > 0;

   // Postcondition: The output consists of lines of integers. The first line

   // is the number n. The next line is the number 2n. The next line is

   // the number 4n, and so on until you reach a number that is larger than

   // 4242. This list of numbers is then repeated backward until you get back

   // to n.

   /* Example output with n = 840:

   840

   1680

   3360

   6720

   6720

   3360

   1680

   840

Explanation / Answer

void pattern(unsigned int n)
{
printf("%u ", n);
if (n < 4242)
pattern(n << 1);
printf("%u ", n);
}