1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Inga [223]
3 years ago
15

Write C++ a function name int min_divisor(int n) that returns the minimum divisor of a number recursively without using any buil

t in C++ classes such as Math.
Computers and Technology
1 answer:
Reptile [31]3 years ago
8 0

Answer:

The program to this question can be given as:

Program:  

#include<iostream> //include header file.  

using namespace std;  

int min_divisor(int n) //define function  

{  

if(n<=0) //if statement (base case)  

{  

return -1; //return value.  

}  

else  

{  

cout<<"Recursive Function call: "<<n<<endl; //print value  

for(int i=2;i<n/2;i++) //loop  

{  

if(n/i==0) //if statement  

{  

return n/i; //return value.  

}  

}  

}  

}  

int main() //main function  

{  

int n; //variable decalration  

cout<<"Enter a number:";  

cin>>n;  

int res=min_divisor(n); //calling function  

cout<<"min divisor is: "<<res<<endl; //print value  

}  

Output:

Enter a number: 5

Recursive Function call: 5

min divisor is: 2

Explanation:

In the above program firstly we include the header file that is iostream. It stands for standard input output stream.Then we declare a function that name is already given in question that is min_divisor(int n). In this function there is a one parameter. In the function we use if-else statement in if block n less then equal to 0 it will return value that is -1. In else block It will print the value first then we use the loop. It starts from the 2 and end from n/2. In this loop we divide the value of n and check that if the value is equal to 0 so it will return n/i. Then we declare the main function in the main function we declare variable in this variable we take user input and pass into the function by calling it and hold the return value of the function into variable res variable and print it.

You might be interested in
Which of these is NOT an advantage of the impact of computer careers.
nikdorinn [45]
I believe the answer could be the first choice. I'm not quite sure, though
4 0
3 years ago
Read 2 more answers
What is your life's meaning??
icang [17]

Answer:

Explanation:

So in the universal perspective, life has no meaning and everything you do. No matter how great or good — will be forgotten or erased forever eventually. In the terms of the natural evolutionary perspective, our meaning is to multiply and survive as long as we can.

5 0
3 years ago
What is defined as a set of machine-readable instructions that directs a computer's processor to perform specific operations?
maria [59]
An executable, a program.
5 0
4 years ago
The Table portion of the Ribbon is made of up three tabs: Design, Layout, and Structure.
konstantin123 [22]

Answer:

False

Explanation:

5 0
4 years ago
In which of the following stages of the development process is a team MOST likely to interview a potential user of an app? A. in
Mrac [35]

Answer:

The correct option is;

A. Investigating and reflecting

Explanation:

In the investigating and reflecting stage, the team involved in the development tries to acquire a thorough and empathic view of the problem the app is meant to solve by researching, the needs of the potential end users of the app so as to isolate the design concept from personal assumption to real world scenarios.

5 0
3 years ago
Other questions:
  • most dialog boxes in windows programs requiring navigation follow a similar procedure. true or false.
    7·1 answer
  • Roy is preparing for his test in English. He creates lots of memory tools and studies using a circuit-learning schedule that he
    13·1 answer
  • Assume that you are able to do an exhaustive search for the key to an encrypted message at the rate of 100 Million trials per se
    12·1 answer
  • ____________ is defined as the set of activities that revolve around a new software product, from its inception to when the prod
    11·1 answer
  • Examine the following algorithm.
    9·1 answer
  • 12. How many different documents can<br> you have open at one time?
    8·1 answer
  • How could you use your technology skill and Microsoft Excel to organize, analyze, and compare data to decide if a specific insur
    12·1 answer
  • A ___ is an online collaborative event that may include such features as chat, slideshows, and PowerPoint presentations.
    8·1 answer
  • Anyone know the friends song by Marshmello? It's stuck in my head.
    12·2 answers
  • What does it mean when it says this person is unavailable on messenger.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!