Write a program that uses a structure to store the following
Solution
#include <stdio.h>
struct airportTraffic //structure
{
int planesLanded;
int planesDeparted;
int greatestPlanes;
int leastPlanes;
};
int main()
{
struct airportTraffic months[12]; //array of structures
int i,totalLanded,totalDeparted,greatest,least,monthg,monthl;
totalLanded = totalDeparted =0;
greatest = 0;
least = 99999;
for(i=0;i<12;i++)
{
printf(\"\ Enter total number of planes landed in month %d:\",i+1);
scanf(\"%d\",&months[i].planesLanded);
printf(\"\ Enter total number of planes departed in month %d:\",i+1);
scanf(\"%d\",&months[i].planesDeparted);
printf(\"\ Enter greatest number of planes landed in a given day in month %d:\",i+1);
scanf(\"%d\",&months[i].greatestPlanes);
printf(\"\ Enter least number of planes landed in a given day in month %d:\",i+1);
scanf(\"%d\",&months[i].leastPlanes);
}
for(i=0;i<12;i++)
{
totalLanded = totalLanded + months[i].planesLanded;
totalDeparted = totalDeparted + months[i].planesDeparted;
}
printf(\"\ The total number of planes landed in a year : %d\",totalLanded);
printf(\"\ The total number of planes departed in a year : %d\",totalDeparted);
printf(\"\ The average number of planes landed in a month : %d\",totalLanded/12);
printf(\"\ The average number of planes departed in a month : %d\",totalDeparted/12);
for(i=0;i<12;i++)
{
if(greatest < months[i].greatestPlanes) //find greatest planes landed among all months
{
greatest = months[i].greatestPlanes;
monthg = i+1;
}
if(least > months[i].leastPlanes) //find lest planes lnded among ll months
{
least = months[i].leastPlanes;
monthl = i+1;
}
}
printf(\"\ The greatest number of planes landed is %d in any one day in month %d \",greatest,monthg);
printf(\"\ The least number of planes departed is %d in any day in month %d \",least,monthl);
return 0;
}
output

