must be a c program using <stdio.h>, <math.h>, <stdlib.h> Write a program that u
ID: 3777552 • Letter: M
Question
must be a c program using <stdio.h>, <math.h>, <stdlib.h>
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. Your program must consist of the following functions: Function getdata - reads and stores the data in the two dimensional array Function averagehigh - calculates and returns the average high temperature for the year Function averagelow - calculates and returns the average low temperature for the year Function indexHighTemp - returns the index of the highest high temperature in the array Function indexLowTemp- returns the index of the lowest low temperature in the array. These functions must all have the appropriate parameter.Explanation / Answer
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
double getdata(double arr[12][2]);
double averagehigh(double arr[12][2]);
double averagelow(double arr[12][2]);
int indexHighTemp(double arr[12][2]);
int indexLowTemp(int arr[12][2]);
int main(int argc, char *argv[]) {
// Disable stdout buffering
setvbuf(stdout, NULL, _IONBF, 0);
double arr[12][2];
getdata(arr[12][2]);
printf("Average High:",averagehigh(arr));
printf("Average Low:",averagelow(arr));
printf("High temp index is:",indexHighTemp(arr));
printf("Low temp index is:",indexLowTemp(arr));
}
double getdata(double arr[12][2]){
int i;
for(i=0;i<12;i++){
printf("Enter high and low temperaturs of month %d",i+1);
scanf("%f %f",&arr[i][0],&arr[i][1]);
}
return arr;
}
double averagehigh(double arr[][]){
double sum = 0;
int i;
for(i=0;i<12;i++){
sum = sum + arr[i][0];
}
return sum/12;
}
double averagelow(double arr[][]){
double sum = 0;
int i;
for(i=0;i<12;i++){
sum = sum + arr[i][1];
}
return sum/12;
}
double indexHighTemp(double arr[][] ){
int i, index=0;
for(i=0;i<11;i++){
if(arr[i][0] < arr[i+1][0]){
index = i+1;
}
}
return index;
}
double indexLowTemp(double arr[][] ){
int i, index=0;
for(i=0;i<11;i++){
if(arr[i][0] > arr[i+1][0]){
index = i+1;
}
}
return index;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.