In: Computer Science
Write a C# Program (using loops) to read temperature of the 7 days of the week (one day at a time) and calculate the average temperature of the week and print it.
using System;
class Temperature
{
static void Main()
{
float sumOfTemp = 0; /*variable to store sum of temperatures and initialize it with 0*/
float temperature; /* variable in which temperature is red from Console */
float average; /*variable to store average */
for (int i = 1; i <= 7; i++) /*run loop seven times to read temperature */
{
/*in each iteration read temperature from console and add it to sum*/
Console.Write("Enter temperature for day " + i + " :: ");
temperature = float.Parse(Console.ReadLine());
sumOfTemp += temperature;
}
average = sumOfTemp / 7; /*calculate average, by diving sum with total elements. Here total elements are 7*/
Console.Write("The average temperature of the week is :: " + average); /*print average*/
}
}
Please upvote if u like answer.