Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write C Program NOT C++ Please Do not write the program if you are not sure abou

ID: 3820641 • Letter: W

Question

Write C Program NOT C++

Please Do not write the program if you are not sure about the answer

2-D Arrays

submit the following a hard copy of the source code (.c file)

Observe the usual guidelines regarding the initial comment section, indenting, and so on. In addition, when functions are required, place function definitions following main. At the beginning of the program and before each function use comments to explain what the function does. Do not use global variables.

2. Yearly rainfall data for four weather stations in a certain county is recorded in the table below.

County Rainfall in Inches

Station

2005

2006

2007

2008

2009

2010

1

39.4

45.6

42.3

44.7

37.3

41.6

2

41.0

47.2

43.8

42.0

36.9

38.2

3

38.1

47.9

42.9

43.6

36.2

42.8

4

41.8

46.5

44.1

45.0

38.1

43.3

Initialize at declaration a double subscripted array of doubles with the rainfall data at the four stations for the six years shown. It may also be convenient to initialize an array of years and an array of station numbers.

Call a function to find the average rainfall for each year. Function parameters will include the two-dimensional array of rainfall data and the one-dimensional array of yearly averages. The number of rows and columns in the array may be defined as symbolic constants or may be passed as array parameters.

Call a second function to find the average rainfall in the county for the 6-year period. Return the overall average pass by value. The array of rainfall data will be a function parameter. The number of rows and columns in the array may be defined as symbolic constants or may be passed as array parameters.

Call a third function to print the labeled table of rainfall data, the yearly averages, and the overall average. Print the yearly averages directly below the column data for the appropriate year. Determine with an if statement the years in which the rainfall was above the overall average; then print.

Station

2005

2006

2007

2008

2009

2010

1

39.4

45.6

42.3

44.7

37.3

41.6

2

41.0

47.2

43.8

42.0

36.9

38.2

3

38.1

47.9

42.9

43.6

36.2

42.8

4

41.8

46.5

44.1

45.0

38.1

43.3

Explanation / Answer

#include <stdio.h>
#define YEAR 6
#define STATION 4
float avg(float rainfall[STATION][YEAR])
{
   float avg = 0;
   int i,j;
   for(i=0;i<STATION;i++)
   {
       for(j=0;j<YEAR;j++)
       {
           avg = avg + rainfall[i][j]; //calculate overall avg
       }
   }
   return avg/24;
}
void avgYearly(float rainfall[STATION][YEAR],float avg[YEAR])
{
   int i,j;
   for(j=0;j<YEAR;j++)
       {
           avg[j] = 0; //initialize avg for 6 years
       }
  
       for(i=0;i<YEAR;i++)
       {
       for(j=0;j<STATION;j++)
       {
           avg[i] = avg[i] + rainfall[j][i]; // add columns in rainfall array
       }
           avg[i] = avg[i]/4;   //average for 4 stations
       }
      
       for(j=0;j<YEAR;j++)
       {
       printf("%.2f ",avg[j]);
       }
}
float print(float rainfall[STATION][YEAR])
{
   int i,j;
   float avgYear[YEAR],avgRainfall;
   printf("----------Rainfall data ----------------- ");
   printf("Station 2005 2006 2007 2008 2009 2010 ");
   for(i=0;i<STATION;i++)
   {
       printf(" %d ",(i+1));
       for(j=0;j<YEAR;j++)
       {
           printf(" %.2f ",rainfall[i][j]);
       }
       printf(" ");
   }
   avgYearly(rainfall,avgYear); //function call
   printf(" Average :");
   for(i=0;i<YEAR;i++)
   {
       printf("%.2f ",avgYear[i]); //display average for 6 years
   }
   avgRainfall = avg(rainfall); // call function to compute overall average
   printf(" Overall average rainfall for 6 years and 4 stations = %.2f ",avgRainfall);
  
   printf(" Years for which rainfall was above overall average : ");
   for(i=0;i<YEAR;i++)
   {
       if(avgYear[i] > avgRainfall)
       printf(" Year : %d Rainfall :%.2f   ",(i+1),avgYear[i]);
   }
  
}
int main(void) {
  
   float rainfall[STATION][YEAR] = {{39.4,45.6,42.3,44.7,37.3,41.6},{41.0,47.2,43.8,42.0,36.9,38.2},{38.1,47.9,42.9,43.6,36.2,42.8},{41.8,46.5,44.1,45.0,38.1,43.3}};
  
   print(rainfall);
   return 0;
}


output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote