Menu

[solved]-C 3 Parts Related Eachother Following Code Prints Elements Array Order Appear Array Simple Q39052179

c++ 3 parts not related to eachother

A) The following code prints all elements in the array a[] inthe order they appear in the array. What is a simple change you canmake to the code, such that the elements are printed in the reverseorder?

1      void  printArrayInOrder(const   double  a[],   int   n)   2     {   3                 if  (n   ==   0)   4                           return;   5   6                cout   <<   a[0]  <<   endl;   7                printArrayInOrder(a   +   1,  n   -­‐   1);   8     }  

————————————————————————————————————————
B) Given two positive integers m and n such that m  <   n, the greatest common divisor of m and n is thesame as the greatest common divisor of m and n-­‐m. Use this factto write a recursive function gcd(). (Suggestion: try a fewexamples on paper prior to writing code.)

int   gcd(int   m,   int  n)   {                                  }  

———————————————————————————————————————-
C) Write a function powerOfTwo that, given a non-negative number x,returns 2x (2^x, or “2 raised to power x”) recursively, assuming 2xis something that can be represented as an integer. Do not use aloop, and do not use the character ‘*’ anywhere in your code.

int   powerOfTwo(int   x)  {                    }

Expert Answer


Answer to c++ 3 parts not related to eachother A) The following code prints all elements in the array a[] in the order they appear… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *