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 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
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...
Rank these aqueous solutions from highest boiling point to lowest boiling point. 1 = highest boiling...
Rank these aqueous solutions from highest boiling point to lowest boiling point. 1 = highest boiling point; 4 = lowest boiling point 0.40 m C2H6O2 0.20 m Na3PO4 0.30 m KNO3 0.20 m C6H12O6  
Rank the following interest rates from lowest to the highest and identify it is a source...
Rank the following interest rates from lowest to the highest and identify it is a source (S) or use (U) of capital. If it is both a source and use of capital, then state both (B) - Federal Funds Rate (FFR) - LIBOR - Interest on Reserves (IOR) - Discount Rate (DR) - Prime Rate - Risk Free Rate - Reverse Repurchase Agreements (Repos)
The highest and lowest birth rates in the United States in 2010 were in Utah and...
The highest and lowest birth rates in the United States in 2010 were in Utah and Maine, respectively. Utah reported 52,258 births with a population of about 2.8 million people. Maine reported 12,970 births with a population of about 1.3 million people. Use this data to answer the following questions. a) On average, how many people were born each day of the year in Utah? b) On average, how many people were born each day of the year in Maine?...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT