0% found this document useful (0 votes)
6 views9 pages

SDP 2 Second Week

The document outlines a programming assignment for a Data Structure and Programming II course, focusing on recursive functions in C++. It includes tasks such as finding the summation of odd numbers, calculating powers, summing squares, and finding minimum elements in arrays using recursion. Additionally, it requires creating a menu-driven program for user interaction and handling input until a specific termination condition is met.

Uploaded by

Da Vy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

SDP 2 Second Week

The document outlines a programming assignment for a Data Structure and Programming II course, focusing on recursive functions in C++. It includes tasks such as finding the summation of odd numbers, calculating powers, summing squares, and finding minimum elements in arrays using recursion. Additionally, it requires creating a menu-driven program for user interaction and handling input until a specific termination condition is met.

Uploaded by

Da Vy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

ពះ ច កកមុ

តិ ស ពះម ក ត

វិទ នបេចកកវិទ កមុ

េដ ៉ តម
ឺ ៉ង ទូគម គមន៍ នង
ិ ប ញ

កិច រ វ វ (GTR-B)

មុខវ ិ : Data Stucture and Programming II

នស
ិ ត
ិ េ ះ ID ពិនុ

SIM DAVY e20230326 …………

POM SREYNEATH e20230364 ………….

VOEUN LYNA e20230961 ..……….

បេ ង នេ យ: Mr. NOP Phearum

ំសិក : ២០២៤ - ២០២៥


TP02: Recursive function
1. Write a recursive function to find the summation of all odd numbers from 1
to n, where n is the input number from the user.
Input:

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.

int finding(int a[ ], int n)


Input:

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.

int find sum(int a[ ], int n)

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.

Example: Suppose a user inputs these numbers: 7, 9, -10, 90, -1.

=> Output: Summation is 95

Input:
Output:

You might also like