1. Global warming . As part of a global warming analysis, a research facility tr
ID: 3532550 • Letter: 1
Question
1. Global warming. As part of a global warming analysis, a research facility tracks outdoor temperatures at the North Pole once a day, at noon, for a year. At the end of each month, these temperatures are entered in to the computer and processed.The operator will enter 28, 29, 30, or 31 data items, depending on the month. You may use -500 as a sentinel value after the last temperature, since that is lower than absolute 0. Your main program should call the read_temps(), hot_days(), and print)temps() functions described here:
a. read_temps() has one parameter, an array called temps, in which to store the temperatures. Read the real data value for one month and store them into the slots of an array. Return the actual number of temperatures read as the result of the function.
b. hot_days(), that has two parameters: the number of temperatures for the current month and an array in which the temperatures are stored. Search through the temp array and count all the days on which the noon temp exceeds 32. Return this count.
c. print_temps(), with the same two parameters plus the count of hot days. Print a neat table of temps. At the same time, calculate the average temperature for the month and print it at the end of the table, followed by the number of hot days.
Explanation / Answer
Executable code
#include<stdio.h>
int A[366];
int read_temps(int temps[])
{
int nA= sizeof(A)/sizeof(A[0]);
int nT= sizeof(temps)/sizeof(temps[0]);
int i=0;
for(i=nA;i<(nT+nA);i++)
{
A[i]=temps[i];
}
return (nT);
}
int hot_days(int num,int temps[])
{
int i=0;
int count=0;
for(i=0;i<num;i++)
{
if(temps[i]>32)
{
count++;
}
}
return count;
}
void print_temps(int num,int temps[],int count)
{
int i=0;
float average=0;
for(i=0;i<num;i++)
{
average=average+temps[i];
printf("%d %d ",(i+1),temps[i]);
}
average=average/num;
printf("Average temperature: %f ",average);
printf("No of hot days: %d ",count);
}
void main()
{
int temps[31];
int i=0,k=0;
while(i<31)
{
printf("Enter temperature or Press -500 for stop ");
scanf("%d",&k);
if(k==-500)
{
break;
}
else
{
temps[i]=k;
}
i++;
}
int a=read_temps(temps);
int b=hot_days(i,temps);
print_temps(i,temps,b);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.