Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * prog.c
- *
- * Created on: Nov 10, 2016
- * Author: dastan.iyembergen
- */
- #include <stdio.h>
- int i;
- typedef struct{
- int rain;
- double t;
- double w;
- } weather;
- int totalRain(weather *p){
- int sum=0;
- for (i=0; i<12; i++){
- sum+=p[i].rain;
- }
- return sum;
- }
- double lowestTemp(weather *p){
- double lowest=p[0].t;
- for (i=1; i<12; i++)
- if (p[i].t<lowest)
- lowest=p[i].t;
- return lowest;
- }
- double aveWind(weather *p){
- double sum=0;
- for (i=0; i<12; i++){
- sum+=p[i].w;
- }
- return sum/12.0;
- }
- void printWeather(weather *p){
- for (i=0; i<12; i++){
- printf("%4i %7.1f %6.1f\n", p[i].rain, p[i].t, p[i].w);
- }
- }
- int main(void) {
- weather *data=(weather*)malloc(12 * sizeof(weather));
- FILE *infile;
- infile=fopen("astana.txt", "r");
- for (i=0; i<12; i++){
- int r;
- double te, wi;
- fscanf(infile, "%i %lf %lf", &r, &te, &wi);
- data[i].rain=r;
- data[i].t=te;
- data[i].w=wi;
- }
- fclose(infile);
- printf("The total rainfall: %4i\n", totalRain(data));
- printf("The lowest temperature: %7.1f\n", lowestTemp(data));
- printf("average wind speed: %6.1f\n\n", aveWind(data));
- printWeather(data);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment