This week in lab they will be writing a few short recursive programs. Write a recursive function that returns the number of digits in a nonnegative integer. For example, it should return 4 if passes the integer 1126 and should return 1 if passed the integer 0. It should take the form: int num_digits(int num); Write a recursive function that computes x raised to the power n. You only need to deal with nonnegative exponents. Thus you can just print out an error message if a negative exponent is passed. Remember that anything raised to the power of 0 is 1. The function should be of the form: double power(double x, int n); Write a recursive function that prints the digits in an integer in reverse order. For example, if passed the integer 1234, it should print "4321". (Hint: use the / and % operations) This function should take the form: void print_rev(int num); Write a recursive function that prints the equivalent number using a different base. It should be passed an decimal integer (base 10) and should be passed the new base. This is calculated by the following approach: 0 Remainder 1 _ 2|1 Remainder 1 _ 2|3 Remainder 0 _ 2|6 Remainder 1 __ 2|13 Remainder 0 __ 2|26 Thus, 26 = 11010(base 2). The function should take the form: void convert_base(int num, int base); Check off the first two in lab and have them turn the other 2 in next week. The following is a sample solution ------------------------------------------------------ #include int num_digits(int num) { if(num > 10) return num_digits(num/10) + 1; else return 1; } double power(double x, int n) { if (n == 0) return 1.0; else if (n > 0) return power(x, n-1) * x; else { cerr << "power has received a negative exponent." << endl; return -1.0; } } void print_reverse(int num) { cout << num%10; int numrest = num/10; if (numrest > 0) print_reverse(numrest); else cout << endl; } void convert_base(int num, int base) { if (num / base == 0) cout << num%base; else { convert_base(num/base, base); cout << num%base; } } void main() { cout << power(2.0, 6) << endl; cout << power(2.3, 4) << endl; cout << num_digits(1) << endl; cout << num_digits(123) << endl; cout << num_digits(12345) << endl; int num = 26; int base = 2; cout << num << " = "; convert_base(num, base); cout << "(base " << base << ")" << endl; num = 32; base = 8; cout << num << " = "; convert_base(num, base); cout << "(base " << base << ")" << endl; print_reverse(12345); print_reverse(9876); }