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 5/16 as a percent
what is 12ft2in = in inches
Suppose that the grade 7 students expect to sell between 100 and 150 hot dogs how many packages of 12 wieners and 8 buns should the students buy if they don't w
factorise completely 2y^2-4y
what word is used to describe the reaction that uses water to break apart a large molecule
Use the term "concentration" in a sentence about liquids that conveys its meaning. (9 points)
6g 300mg-5g 200mg is equal to?
according to Carnegie what were the revolutionary changes that made it possible for the poor to enjoy what the rich could not before afford?
private individuals and companies decide what products to manufacture and what prices to change for goods and services with no government involvedment
in the 1760's, americans in the original 13 british colonies began to protest against