destadams6822 destadams6822
  • 25-11-2020
  • Computers and Technology
contestada

Write the definition of a void function that takes as input an integer and outputs two times the number if it is even; otherwise it outputs five times the number.

Respuesta :

MrRoyal
MrRoyal MrRoyal
  • 25-11-2020

Answer:

Written in C++

void number(int n){

if(n%2 == 0)

cout<<2 * n;

else

cout<<5 * n;

}

Explanation:

The programming language is not stated.

However, I answered using C++

This line defines the function as void

void number(int n){

This line checks if the number is even

if(n%2 == 0)

If yes, it doubles the number and prints the output

cout<<2 * n;

If otherwise,

else

It multiplies the number by 5 and prints the output

cout<<5 * n;

}

To call the function from main, use:

number(n);

Note than n must be declared as integer

See attachment

Ver imagen MrRoyal
Answer Link

Otras preguntas

What is a common introductory question to which "Muy bien, gracias." would be an appropriate response? Mark this and retum Save and Exit Next Submit
answer this question ASAP
The graph represents f(x) = (x1+3. What is f(-2.2)? O-2 5 ОО 4 0 1 02 0-3 2. 1 -3 -2 -1 1 2 3 4 5 x . - 2 -3 -5
No.3 plzz ...?Any one ​
HELP WILL MARK BRANLIEST. During the process of demographic transition, a movement from stage 1 to stage 2 is most likely caused by A)social changes B)improved
HURRYYYYYYYYYYYYYY PLZZZZ
what is the adverb form of medicine​
What challenge did newly independent countries have to face as a result of unchanged colonial boundaries? The boundaries ignored the presence of mountains and r
Match the equation on the left with the appropriate solution on the right.
5. Facts of how the United States became an imperialist in the past and is still one today.