SDP 2 Second Week
SDP 2 Second Week
តិ ស ពះម ក ត
េដ ៉ តម
ឺ ៉ង ទូគម គមន៍ នង
ិ ប ញ
កិច រ វ វ (GTR-B)
នស
ិ ត
ិ េ ះ ID ពិនុ
Output:
2. A C++ program that can perform various mathematical operations below. Solve
each operation using a recursive operation.
a. A power function to calculate 𝑚 . It is m multiply m for n times (m*m*…*m)
int power(int m, int n)
b. A function to calculate the sum of the square of the first n integer 12+22+…+n2.
int square(int n)
c. Sum the digits of a number.
int sumDigit(int n)
Input:
Output:
3. A C++ Program that can do some operations below. (make a menu for your
program so users can test any functions. Run it as an infinite loop). Solve each
operation using a recursive operation.
a. A function to display n star (*) void display star(int n)
b. Display numbers from n to 1 void display numbers(int n)
Input:
Output:
4. Write a recursive function that finds and returns the minimum element in an array,
here the array and its size are given as parameters.
Output:
5. Write a recursive function that computes and returns the sum of all elements in an
array, where the array and its size are given as parameters.
Input:
Output:
6. Write a recursive program using C++ language to ask many numbers from a user
(ask the user to input one number then ask again and again). When the user inputs
number -1, the program stops asking the user for more numbers. Display the total
summation of all input numbers.
Input:
Output: