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
grandymaker [24]
2 years ago
9

Write the definition of a void function that takes as input two integer values, say n and m. The function returns the sum and av

erage of all the numbers between n and m (inclusive).
Computers and Technology
1 answer:
hodyreva [135]2 years ago
7 0

Answer:

void mn(int m, int n){

   int sum = 0;

int count = 0;

   if(m<n){

       for(int i = m;i<=n;i++){

           sum+=i;

       }

   }

   else{

       for(int i = n;i<=m;i++){

           sum+=i;

       }

   }

count = abs(m - n)+1;

   cout<<"Sum: "<<sum<<endl;

   cout<<"Average: "<<(float)sum/count;

}

Explanation:

This line defines the method

void mn(int m, int n){

This initializes sum and count to 0

   int sum = 0;

int count = 0;

This checks if m is less than n

   if(m<n){

This iterates from m to n and calculates the sum of numbers between this interval

<em>   for(int i = m;i<=n;i++){</em>

<em>            sum+=i;</em>

<em>        }</em>

<em>    }</em>

If otherwise,

   else{

This iterates from n to m and calculates the sum of numbers between this interval

<em>        for(int i = n;i<=m;i++){</em>

<em>            sum+=i;</em>

<em>        }</em>

<em>    }</em>

This calculates the range from m to n using absolute function

count = abs(m - n)+1;

This prints the calculated sum

   cout<<"Sum: "<<sum<<endl;

This calculates and prints the average

   cout<<"Average: "<<(float)sum/count;

}

<em>See attachment for complete program that includes the main (in c++)</em>

Download cpp
You might be interested in
How long will the plant have been dead when 87.5 percent of its C-14 has become N-14?
nikdorinn [45]

Answer:

50% - one half life — 5,730 years

25% — two half lifes — 11,460 years

12.5% — three half lifes — 17,190 years

6.25% — four half lifes — 22,920 years

3.125% — five half lifes — 28,650 years

Explanation:

8 0
2 years ago
When forced distribution is used to reduce leniency bias, this can cause __________ if a pfp system is in place?
ziro4ka [17]
When forced distribution is used to reduce leniency bias, this can cause <decreased trust> between employees if a pfp system is in place.
3 0
3 years ago
Why students might want headsets for their computers?
VARVARA [1.3K]
It can be noisy and distracting to students to listen to audio speakers when there are multiple computers in the classroom. Headphones help the students
3 0
3 years ago
What does cro stand for?
mr_godi [17]
It stands for Chief Risk Officer 
8 0
2 years ago
Read 2 more answers
Alright, so im currently trying to pass a computer science class. i need it done in a little under 2 weeks. Ill just ask the one
Alla [95]

Answer:

B. Mesh

Explanation:

5 0
2 years ago
Other questions:
  • All languages from the second generation on must be translated into machine language for the computer to be able process the inp
    8·1 answer
  • John works for Internal Computer Specialists, which focuses on helping small business owners resolve MIS infrastructure issues.
    12·1 answer
  • Determine the number of bytes necessary to store an uncompressed RGB color image of size 640 × 480 pixels using 8, 10, 12 and 14
    11·1 answer
  • You should use html elements instead of server controls when
    11·1 answer
  • You are working on an excel table and realize that you need to add a row to the middle of your table. what is one way to do this
    12·1 answer
  • . Identify an emerging crime issue in your community using data available from sources such as local newspapers, online police r
    6·1 answer
  • Suppose you have one particular application that is trying to send data on the Internet but none of the data is making it to the
    15·2 answers
  • Suppose there is a class Alarm. Alarm has two class variables, code which contains a String value representing the code that dea
    12·1 answer
  • The
    6·1 answer
  • MULTIPLE COICE! BRAINLIEST
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!