Simple Weather Report – C


#include<stdio.h>
#include<stdlib.h>
#define YEARS 3
#define MONTHS 12
int main()
{
float rain[YEARS][MONTHS] = 
{
{1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9,2.0},
{2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1},
{3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2},
};
int year; 
int month;
float total, subtot;
printf("YEARttRAINFALL (inches)n");

for(year = 0, total = 0; year < YEARS; year++){
for(month = 0, subtot = 0; month < MONTHS; month++){
subtot += rain[year][month];

}
printf("%3dtt%9.1fn", 2021 + year, subtot);
total += subtot;

printf("nThe yearly average is %.1f inches.nn", total/YEARS);

}
return 0;
}

Scroll to top