Ask Question
12 June, 01:49

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.

+3
Answers (1)
  1. 12 June, 02:28
    0
    The answer for the given question is:

    total=0; / / initialize the variable "total" to 0

    for (k=0; k
    total + = temps[k];

    }

    avgTemp = total/n; / /the answer will be stored in "avgTemp" variable

    Explanation:

    Here, we set variable "total" and initialize to 0.

    Then, we set the for loop which starts from 0 and stops at "n".

    After, that we calculate the average temperature and store the result of calculation in "avgTemp" variable.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given an array temps of double, containing temperature data, and an int variable n that contains the number of elements in temps: Compute ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers