Question #48753

Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year.

Expert's answer

#include <stdio.h>
int main(){
char *month[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
double temperature[12][2];
double average_min=0, average_max=0, min=100, max=-100;
int i, min_month, max_month;
for (i = 0; i < 12; i++){
printf("%s [min, max] ", month[i]);
scanf("%lf", &temperature[i][0]);
scanf("%lf", &temperature[i][1]);
}
for (i = 0; i < 12; i++){
average_min += temperature[i][0];
average_max += temperature[i][1];
if (min>temperature[i][0]){ min = temperature[i][0]; min_month = i; }
if (max<temperature[i][1]){ max = temperature[i][1]; max_month = i; }
}
average_max /= 12; average_min /= 12;
printf("\nAverage high: %.2lf\n", average_max);
printf("Average low: %.2lf\n", average_min);
printf("Highest temperature: %.2lf (%s)\n", max, month[max_month]);
printf("Lowest temperature: %.2lf (%s)\n", min, month[min_month]);
getchar(); getchar();
return 0;
}


http://www.AssignmentExpert.com/</stdio.h>

LATEST TUTORIALS
APPROVED BY CLIENTS