Write in C. Given an array temps of double, containing temperature data, and an int variable n that contains the number of elements in temps: Compute the average temperature and store it in a variable called avgTemp. Besides temps, n, and avgTemp, you may use only two other variables -- an int variable k and a double variable total, which have been declared.

Respuesta :

Answer:

#include <stdio.h>

int main()

{  

   int n = 5;

   double temps[5] = {10.1, 6.4, 14.9, 8.8, 9.2};

   

   double avgTemp, total = 0;

   

   for (int k=0; k<n; k++) {

       total += temps[k];

   }

   avgTemp = total / n;

   

   printf("%lf", avgTemp);

   return 0;

}

Explanation:

Initialize the variables as described in the question

Create a for loop that iterates through the temps array

Inside the loop, add the temperature values in temp to the total

When the loop is done, calculate the average - divide the total by n

Print the average