Explanation of Solution
- a. Recursive method to print odd numbers between 1 to n:
/**********************************************************
* This program demonstrates functionality of recursive *
* function recursive_odd() *
**********************************************************/
//Select header files
#include <iostream>
using namespace std;
//Function prototype
void recursive_odd(int n);
The “main()” function reads an integer number from user and call recursive function to display odd numbers between “1” and “n”...
Explanation of Solution
- b. Recursive method to print odd numbers between “n” and 1:
Program:
/**********************************************************
* This program demonstrates functionality of recursive *
* function recursive_odd_n_1() *
**********************************************************/
//Select header files
#include <iostream>
using namespace std;
//Function prototype
void recursive_odd_n_1(int n);
The “main()” function reads an integer number from user and call recursive function to display odd numbers between “n” and “1”...
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
- Java - Write an iterative method that calculates the SUM of all integers between 1 and a given integer N (input into the method). Write a corresponding recursive solution. (return answer, don’t print)arrow_forwardUsing Java, write a function that calculates the factorial of a number N using recursive and non-recursive methods. Call both methods with multiple numbers and show that the results are the same.arrow_forwardWrite a recursive method that gives the following pattern(Write in Java language) run : 1 2 4 7 11 16 22 29 37 46arrow_forward
- Write a recursive Java method that calculates the sum of n positive integer numbers. The math function is: f(n) = 1 + 2 + 3 + … + n. Code: public static int Func(int n) { if (n <= 1) return n; return n + Func(n - 1); } Has an error.arrow_forwardwrite a recursive method that performs exponentiation raising a base to a power (the only math operations you are allowed to use are addition and subtraction) JAVA PLEASEarrow_forwardWrite a recursive method that displays all permutations of a given array ofintegers. Here is a sample run: Enter the array size : 3[1, 2, 3][1, 3, 2][2, 1, 3][2, 3, 1][3, 1, 2][3, 2, 1]arrow_forward
- Write a program that will contain the following methods: printSub1, printSub2, printSub3, printSub4 – print all substrings of S using recursion. For example, if S = "abcd": printSub1 will print "a", "ab", "abc", "abcd", "b", "bc", "bcd", "c", "cd", "d" printSub2 will print "d", "cd", "bcd", "abcd", "c", "bc", "abc", "b", "ab", "a" printSub3 will print "a", "b", "c", "d", "ab", "bc", "cd", "abc", "bcd", "abcd" printSub4 will print "abcd", "bcd", "abc", "cd", "bc", "ab", "d", "c", "b", "a" Note that the actual output will not have quotation marks around the substrings. The substrings must print in the order shown for each method. You may only use these String methods in your work: length(), substring() Your main method in this program should provide an appropriate menu which allows the user the enter the string of their choice and pick any of the print substring options they want. write the methods recursively and in javaarrow_forwardWrite a program that will contain the following methods: printSub1, printSub2, printSub3, printSub4 – print all substrings of S using recursion. For example, if S = "abcd": printSub1 will print "a", "ab", "abc", "abcd", "b", "bc", "bcd", "c", "cd", "d" printSub2 will print "d", "cd", "bcd", "abcd", "c", "bc", "abc", "b", "ab", "a" printSub3 will print "a", "b", "c", "d", "ab", "bc", "cd", "abc", "bcd", "abcd" printSub4 will print "abcd", "bcd", "abc", "cd", "bc", "ab", "d", "c", "b", "a" Note that the actual output will not have quotation marks around the substrings. The substrings must print in the order shown for each method. You may only use these String methods in your work: length(), substring() Your main method in this program should provide an appropriate menu which allows the user the enter the string of their choice and pick any of the print substring options they want. IN JAVAarrow_forwardWrite a short recursive Java method that rearranges an array of integer values so that all the even values appear all before odd values programming language: java Need full code with explanationarrow_forward
- In java, Write a recursive method for printing n box shapes [] in a row. Hint: Print one []; then print n - 1 of them.arrow_forwardWrite a recursive program in Java to find the sum of integers from -100 to 0 and display the sum in the output.arrow_forwardWrite a recursive method to print all the permutations of astring. For example, for the string abc, the permutation isabcacbbacbcacabcba public static void displayPermutation(String s)public static void displayPermutation(String s1, String s2)The first method simply invokes displayPermutation(" ", s). The secondmethod uses a loop to move a character from s2 to s1 and recursively invokesit with new s1 and s2. The base case is that s2 is empty and prints s1 to theconsole.Write a test program that prompts the user to enter a string and displays all itspermutations.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education