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
Which of the following statements is true?
nignag [31]

Answer:

Option D is the correct answer.

Explanation:

6 0
3 years ago
A typical analog cell phone has a frequency of 850 mhz; a digital phone a frequency of 1950 mhz. compared to the signal from an
Zepler [3.9K]
A higher frequency than the analog cell phone.
5 0
3 years ago
Cindy tried to delete a customer but the customer still had open invoices so the system would not allow her to delete the custom
Verdich [7]

Answer:

The answer is "Referential integrity".

Explanation:

This relates to one aspect of data integrity. Data across multiple tables are linked via relationships. In view of the distinct customer & invoice tables, each invoice table should have the primary key specified throughout the Customer table, for instance. Whenever the invoice table contains a customer ID reference. This ID including its customer will be only a table of the customer.

8 0
3 years ago
9.A major step before taking print of the document is (3 points)
olya-2409 [2.1K]

Answer:

Uhyuuuuufuddirueueurururururru

8 0
2 years ago
A Python function cannot under normal circumstances reference a module variable for its value.
marishachu [46]
This is false because
6 0
3 years ago
Read 2 more answers
Other questions:
  • What type of survey can help a network administrator make decisions about bands, channels, and widths when installing new access
    9·1 answer
  • )in the link based implementation of the ADT sorted list what is the worst case time efficiency of the remove method?
    7·1 answer
  • On other questions, how do I write my own question, without commenting on others questions? It is only allowed two, I think, the
    13·1 answer
  • Which of the following branches of government is NOT involved in Discretionary Fiscal Policy?
    8·1 answer
  • You are required to write a calculator for Geometric shapes(Circle, Square, and Rectangle). The basic idea is that you willprovi
    7·1 answer
  • Hard light is usually not good for filming. True False
    11·2 answers
  • Whitch event describes a festival in rio, brazil that includes a samba parade and eccentric outfits?
    13·1 answer
  • Modify class Time2 of fig 8.5, (which is split into four pictures) to include a tick method that increments the time stored in a
    8·1 answer
  • Combining two or more cells to make one is called​
    8·1 answer
  • Which of these lines of code will increment a variable?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!