I want to find the months with max precipitation and min pre

I want to find the months with max precipitation and min precipitation. What should be typed instead of b and c ?

int i; float sum, avg, max, min, b, c; float precipitation [12]; printf \"MonthltAverage Precipitation n\'\'); for (i30; i 12 i++) printf &dlt;\", +1) Can (\"Sf\'\', precipitation [i]) sum sum precipitation il avg sum 12 printf (\"\ Average precipitation for 12 months &0.2f\ \'\', avg) max precipitation [01 for (i F0 i 12 i++) if (precipitation li max) max precipitation i i printf (\"AnMonth with maximum precipitation of $0.2f inches is sd\ \ \", max, b) min precipitation 10 for i 0 i 12; i++) if (precipitation i min) min precipitation [i]; printf (\"Month with minimum precipitation of $0.2 f inches is &d;\",min, c)

Solution

You should keep track of max and min index in loop and assign loop index of max and min to b and a respectively.a and b should be int not float to store month number

==========================================================

#include<stdio.h>
int main(int argc, char const *argv[])
{
   int i;
   float sum,avg,max,min;
   int a,b;
   float precipitation[12];
   printf(\"Month\\tAverage Precipitation\ \");

   for ( i = 0; i < 12; ++i)
   {
       printf(\"%d\\t\",i+1 );
       scanf(\"%f\",&precipitation[i]);
       sum=sum+precipitation[i];
   }

   avg=(float)sum/12.0;

   printf(\"Avearage precipitation for 12 months : %0.2f\ \",avg );

   max=precipitation[0];

   for ( i = 0; i < 12; ++i)
   {
       if(precipitation[i]>max)
       {
           max=precipitation[i];
           b=i;
       }
   }

   printf(\"\ Month with maximum precipitation of %0.2f inches is %d\ \ \",max,b );


   min=precipitation[0];

   for ( i = 0; i < 12; ++i)
   {
       if(precipitation[i]<min)
       {
           min=precipitation[i];
           a=i;
       }
   }

   printf(\"\ Month with minimum precipitation of %0.2f inches is %d\ \ \",min,a );
  

   return 0;
}

==========================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Month   Average Precipitation
1   23.2
2   32.4
3   32.1
4   32.3
5   23.2
6   43.2
7   23.4
8   21.3
9   43.2
10   12.3
11   12.4
12   43.2
Avearage precipitation for 12 months : 28.52

Month with maximum precipitation of 43.20 inches is 5


Month with minimum precipitation of 12.30 inches is 9

I want to find the months with max precipitation and min precipitation. What should be typed instead of b and c ? int i; float sum, avg, max, min, b, c; float p
I want to find the months with max precipitation and min precipitation. What should be typed instead of b and c ? int i; float sum, avg, max, min, b, c; float p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site