Question

3. 5 a [DO NOT USE ANY VARIABLES Write a C++ function that takes two integer parameters (a and b) and prints a list of all the integers between a and b-1 (inclusive). one (2, 12) should print 2 34567 8 9 10 11. one (2, 13) should print 2 34567 8 9 10 11 12 b. [D NOT USE ANY VARIABLES Write a C++ function that is the same as the first one, except that it only prints out the numbers between a and b-1 that b is exactly divisible by two (2, 12) should print 2 346. two (2, 13) should print nothing. C. [DO NOT USE ANY VARIABLES] Write a C++ function that is very similar to the second one, except that it doesnt print anything, it just returns as its result the number of things that two would print. three(2, 12) returns 4, because two(2, 12) prints four things three(2, 13) returns 0, because two(2,13) prints nothing. Hint: If this seems a little tricky, first write a function that would return true if two would print anything at all, and false if two would print nothing. d. [D NOT USE ANY VARIABLES] You are probably aware that a number that has no divisors except for 1 and itself is called a prime number Using your previous answers, write a function that takes one integer parameter n, and if n is prime prints out the word prime, and if n is not prime prints out all the divisors of n. four(11) ohould print prime four (12) should print 2 3 46 four (13) should print prime four(14) should print 2 7See the image below and write the code using C++, without using variables, only recursion.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

void one(int, int);

void two(int, int);

int main() {

cout<<"Function 1"<<endl;

one(2,13);

cout<<endl;

cout<<"Function 2"<<endl;

two(2,12);

cout<<endl;

return 0;

}

//Recursion method that calls itself to print the between numbers

void one (int a, int b){

if(a<b){

cout<<a++<<" ";

one(a, b);

}

}

//Recursion method that prints the factors

void two (int a, int b){

if(a<b){

if(b%a == 0){

cout<<a<<" ";

}

a++;

two(a, b);

}

}

Output:

CUsers devak Documents\Untitled1.exe Function 1 2 3 4 5 6 7 8 9 10 11 12 Function 2 2 3 4 6 Process returned e (exe) xecution

Add a comment
Know the answer?
Add Answer to:
See the image below and write the code using C++, without using variables, only recursion. 3....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use C programming Make sure everything works well only upload Write a program that takes an...

    Use C programming Make sure everything works well only upload Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2:\n". If the user's input is less...

  • C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all...

    C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all the numbers less that the parameter that are divisors of the parameter (i.e. divides it without a remainder) including 1. So printdivisors(6) will print 1,2,3. Note you may use a wrapper function or default parameters. (b) Write a function, sumdixisors, that takes a single integer parameter and returns the sum of all the divisors of the parameter (including 1). So sumdivisors(6) will return 6...

  • Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument,...

    Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is a vector containing all prime numbers between 2 and n, inclusive. Verify the correctness of your code with inserting 13 as the input argument, and check that your output is Primes = [2,3,5,7,11,13]. You are NOT allowed to use any directly relevant MATLAB built-in function such as divisors, etc. NOTE: A prime number is a...

  • PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a...

    PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...

  • use java and write in text a. Rewrite the following code segment using if statements. Assume...

    use java and write in text a. Rewrite the following code segment using if statements. Assume that grade has been declared as of type char. char grade= 'B';; switch (grade) { case 'A': System.out.println("Excellent"); break case 'B': System.out.println("Good"); default: System.out.println("you can do better”); } - b. write Java code that inputs an integer and prints each of its digit followed by ** e.gif the integer is 1234 then it should print 1**2**3**4 e.g. if the integer is 85 then it...

  • c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input:...

    c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and,...

    Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and, on the output, writes the sum of the divisors of n (other than itself). For integers less than or equal to 1 it should print 0. For example, the input -3 0 1 4 5 6 12 should generate the output 0 0 0 3 1 6 16 Explanation of output: The input -3 is less than 1, output is 0. The input 0...

  • C++ ONLY Write a function calculator that takes two floating numbers and one operator and prints...

    C++ ONLY Write a function calculator that takes two floating numbers and one operator and prints out the answer based on arithmetic. Assume that there are no overflow, underflow and division by zero cases. Your function should be named calculator Your function takes three input parameter: two double numbers and one char operator Your function does not return anything Your function prints answer in the format specified below Your function should set precision point to 2 Note: You must use...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT