Question

Please follow the detailed instructions for c programming , note that struct type is not allowed :

Best Practices for Code Style Your submissions must observe the following guidelines. Submissions which do not meet the guide- lines will have marks deducted, even if they function correctly (although some of the guidelines, such as those relating to uninitialized memory, might also affect the ability of the program to worlk correctly on a reliable basis, which could result in a deduction for both style and function). » Submitted files must be syntactically correct and named according to the assignment speci- Every source file must contain a comment (at or near the top of the file) with your name, » The goto statement is not permitted in any assignment submissions. Instead, your code fication. student number, the date the code was written and a brief description of the program. should use structured control flow elements, like if, for and while. . Global variables (data variables created outside of the scope of a function) are not permitted, except when explicitly allowed by the assignment. For this assignment, no global variables are permitted, except for const variables if needed. » Every function with a non-void return type must return a value. » Uninitialized variables may not be used before being assigned a value. » Every file opened (by functions such as fclose) must be explicitly closed (by a call to fclose).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you find this helpful, then please leave a like.

CODE:

#include <stdio.h>
#include <stdlib.h>

int main()
{
float temperature[12][31],dailytemp; //I am using a 2d array to keep track of the daily temperature readings
int count[12][31]; //This array keeps a count of the number of reading taken on a particular month/day. This is needed in the final calculation of average temperature
int i,month,day,hour,minute,station_number;
for(i=0;i<12;i++) //Initializing both the arrays
{
int j;
for(j=0;j<31;j++)
{
temperature[i][j]=0;
count[i][j]=0;
}
}
FILE *fin;
fin=fopen("input_data.txt","r"); //Opening the input file
FILE *fout;
fout=fopen("daily_averages_summary.txt","w"); //Opening the output file
while(fscanf(fin,"%d %d %d %d %d %f",&month,&day,&hour,&minute,&station_number,&dailytemp)!=EOF) //Reading the input file line by line until end of file
{
temperature[month-1][day-1]+=dailytemp; //Updating the daily temperature sum
count[month-1][day-1]++; //Incrementing the number of readings taken on that day
}
for(i=0;i<12;i++)
{
int j;
for(j=0;j<31;j++)
{
if(count[i][j]!=0) //If a reading is present on that particular month/day
{
float k=temperature[i][j]/count[i][j]; //Calculating the average temperature of month/day
fprintf(fout,"%d %d %.2f\n",i+1,j+1,k); //Outputting it to the file
}
}
}
fclose(fin); //Closing files
fclose(fout);
return 0;
}

OUTPUT:

CAUsers\Greenoe\ Documents\Coding\Ch Process returned 0 (0x execution time: 0.063 s Press any key to continue.

daily averages ...-X File Edit Format View Help 2 28 -0.75 3 10 7.30 3 11 8.73 6 10 18.70

Add a comment
Know the answer?
Add Answer to:
Please follow the detailed instructions for c programming , note that struct type is not allowed...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT