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.
1

Expert's answer

2014-11-10T11:00:46-0500
#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>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS