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

Which represents the smallest number? A. 3.8 x 10^7 B. 3.8 C. 3.8 x 10^−18 D. 3.8 x 10^15
Find the product 876 greater or equal to 65 =
a square pyramid with a base area of 16 square feet and a cube with a side length of 4 feet have equal volumes. what is the height of the pyramid?
Jake concluded that the runoff had little effect on the dissolved oxygen levels, and Aisha concluded that the runoff had a major effect on dissolved oxygen leve
In the chemical formula for magnesium chloride,mgcl what does the subscript 2 represent
Compared to water, ice has a lower ____ , which allows it to float
P PQR= - 48 - 132 - 180
Solve this jjejsjssldhdjdjdksjsjsjs
How were the people of the Ukraine killed? A. Death Camps B. Labor Camps C. Exposure and Disease D. Mass starvation engineered by Stalin
most scientists agree that there is no single ______________ for solving problems