Language: C Using the recursion, show all different ways to represent an integer N as sum of non-zero natural numbers. For example, for N = 3, you have the following possibilities: 3, 2 + 1, 1 + 2, 1 + 1 + 1. Problem 2

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 12PE
icon
Related questions
Question

 

Language: C

Using the recursion, show all different ways to represent an integer N as sum of non-zero natural numbers. For example, for N = 3, you have the following possibilities: 3, 2 + 1, 1 + 2, 1 + 1 + 1.

Problem 2

Problem 1:
Write a program to reverse an array using recursion.
a) Declare an array of N integers. Use the preprocessor #define directive for the size of the
array. Fill it with pseudorandom numbers.
b) Define the recursive procedure, that reverses the array by swapping the last with the first ele-
ment, and then recursively swapping the remaining subarray. To this end, define the function void
reverseArray (int *inputArray, int leftIndex, int rightIndex). The function should stop
the recursion, whenever left Index >= rightIndex.
c) Print your original, and the reversed array. Test your results for both even, and for odd N.
Problem 2:
Using the recursion, show all different ways to represent an integer N as sum of non-zero natural
numbers. For example, for N = 3, you have the following possibilities: 3, 2+1, 1+2, 1+1+1.
Transcribed Image Text:Problem 1: Write a program to reverse an array using recursion. a) Declare an array of N integers. Use the preprocessor #define directive for the size of the array. Fill it with pseudorandom numbers. b) Define the recursive procedure, that reverses the array by swapping the last with the first ele- ment, and then recursively swapping the remaining subarray. To this end, define the function void reverseArray (int *inputArray, int leftIndex, int rightIndex). The function should stop the recursion, whenever left Index >= rightIndex. c) Print your original, and the reversed array. Test your results for both even, and for odd N. Problem 2: Using the recursion, show all different ways to represent an integer N as sum of non-zero natural numbers. For example, for N = 3, you have the following possibilities: 3, 2+1, 1+2, 1+1+1.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning