Respuesta :

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

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

           sum+=i;

       }

   }

If otherwise,

   else{

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

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

           sum+=i;

       }

   }

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;

}

See attachment for complete program that includes the main (in c++)

Ver imagen MrRoyal
RELAXING NOICE
Relax