Question

In: Computer Science

How to find the day of the highest and lowest temperatures? And how to find an...

How to find the day of the highest and lowest temperatures? And how to find an average of high and low temperatures? C language

Solutions

Expert Solution

You can use a loop to find the maximum, minimum & average temperatures respectively as shown below:

Assuming that the temperature readings are stored in an array of chronological order, we can loop through all of the elements of that array and keep updating the min & max temperatures that we have found till the current iteration. The index of these elements will represents the day.

The following code shows all these operations:

Sample Code:

#include <stdio.h>

int main()
{
float tempratures[5] = {25, 10, 14, 35, 45}; //Initialize random temprature values in daily chronological order
float max_t, min_t, avg_t;
int min_day, max_day;
max_t = tempratures[0]; //Initialize max & min tempratures to first day's temprature
min_t = tempratures[0];
min_day = 0;
max_day = 0;
for (int i = 0; i < 5; i++)
{
if (tempratures[i] < min_t) {
min_t = tempratures[i];
min_day = i+1; //Update day to i+1 to represent the day in order
} if (tempratures[i] > max_t)
{
max_t = tempratures[i];
max_day = i+1;
}
}
printf("Day of highest temperature: %d\n", max_day);
printf("Day of lowest temperature : %d\n", min_day);
avg_t = (max_t + min_t) / 2;
printf("Average temperature = %.2f\n", avg_t);
}

OUTPUT:

(*Note: Please up-vote. If any doubt, please let me know in the comments)


Related Solutions

Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. These methods MUST be your original code.   Your program should output all the values in the array and then output the average high and the...
Write a program that uses a two dimensional array to store the highest and lowest temperatures...
Write a program that uses a two dimensional array to store the highest and lowest temperatures for each month of the calendar year. The temperatures will be entered at the keyboard. This program must output the average high, average low, and highest and lowest temperatures of the year. The results will be printed on the console. The program must include the following methods: A method named inputTempForMonth whose purpose is to input a high and a low temperature for a...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In c++ Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value). The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In c++ Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value). The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In C++ c. The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function indexLowTemp: This function returns the index of the lowest low temperature in the array. These functions must all have the appropriate parameters.
How do you rate the acidity from highest to lowest for acids ( carboxylic acids and...
How do you rate the acidity from highest to lowest for acids ( carboxylic acids and alcohol) ? How do you rate nucleophilic strength ? How do you rate the reactivity of a carbonyl receiving a backside attack? how do you rate the boiling points of carboxylic acids, amides, esters, alcohols rank solubility of carbaldehyde , carboxyilic acid ester in water
If bandwidth is the difference between the highest and lowest signals of a transmission, then this...
If bandwidth is the difference between the highest and lowest signals of a transmission, then this means that a signal with the lowest frequency of 10KHz and an upper frequency of 5MHz, has a bandwidth of _____KHz. If a data signal bit rate is 5kbps, then at Harmonic 1 we would have a value of ______ Hz, at Harmonic 3 we would have a value of _____Hz, and at Harmonic 5 wed would have a value of ____ Hz. The...
Which of the following is listed in the correct order, from the highest to the lowest...
Which of the following is listed in the correct order, from the highest to the lowest taxonomic unit?
which has the highest and lowest EN [ Cl, P, Br]
which has the highest and lowest EN [ Cl, P, Br]
The lowest and highest observations in a population are 14 and 48, respectively. What is the...
The lowest and highest observations in a population are 14 and 48, respectively. What is the minimum sample size n required to estimate μ with 90% confidence if the desired margin of error is E = 1.5? What happens to n if you decide to estimate μ with 95% confidence? (You may find it useful to reference the z table. Round intermediate calculations to at least 4 decimal places and "z" value to 3 decimal places. Round up your answers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT