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

water would be considered a ?
f(x) = 3x + 9, g(x) = 5x2 Find (f + g)(x).
what is the best estimate for the product of 289 and 7?
602 < 620 correct? Which way is greater than < or >?
A physician has ordered 0.50 mg of atropine, intramuscularly. If atropine were available as 0.10 mg/mL solution, how many mL would u need to give?
what is the fraction of 1/5
if two objects of the same size will always have the same mass?
Perry Deposited 8,250 into a savings account 13 years ago. The account has an interest rate of 4.7% and then balance is currently 14,988.59. how often does the
how would I figure out the answer to number 13? because every time I redo it I get a different answer.
Which of the following is a solution of x2 − 10x = –36? negative 5 minus i square root of 10 5 plus i square root of 61 negative 5 minus i square root of 11