title: Display two array elements in C
body: <p>I need to show the matching &quot;dates&quot; element with the &quot;values&quot; element. I'm having trouble trying to show the two arrays' elements together. For example, I need to get the highest rainfall value to show the year and month it occurred. Same with lowest etc. I have used a for loop to find the highest and lowest values of rainfall that occurred but I am unsure on how to print the corresponding date.</p>
  <p>I think I am on the right track but have gotten to this point and don't know what to do!</p>
  <p>I would appreciate some help with this and maybe some tips to keep in my mind if you have any to share. P.S I'm new to stackoverflow.</p>
  <p><a href="https://i.stack.imgur.com/QNXfx.png" rel="nofollow noreferrer">Example when executed</a></p>
  <p>My code so far:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
      
  int main()
  {
      // Data Declaration
      char header[40] = &quot;&quot;;
      int size_of_array = 768;
      int dates[768] = {0};
      float values[768] = {0};
      float sum = 0;
      float sum1 = 0;
      float avg;
      int i;
      float largest, lowest;
      FILE *input_fptr;
      
      //  Opens file
      input_fptr = fopen(&quot;rainfallupdated.csv&quot;, &quot;r&quot;);
      if( input_fptr == NULL )
      {
          printf( &quot;Error - could not open the file\n&quot;);
          return 1;
      }
      
      // Read in the header line from file
      fgets(header, sizeof(header), input_fptr);
      printf(&quot;%s&quot;, header);
      
      // Read 768 lines of data from the file
      for( i=0; i &lt; size_of_array; i++)
      {
          fscanf(input_fptr, &quot;%d,%f\n&quot;, &amp;dates[i], &amp;values[i]);
          printf( &quot;%d\t %g\n&quot;, dates[i], values[i]);
      
      }
      fclose(input_fptr);
      
      // Information for the user
      printf(&quot;YearMonth , Rainfall in mm\n&quot;);
      printf(&quot;\n&quot;);
      printf(&quot;Example: 198702 -&gt; February of 1987.\n&quot;);
      printf(&quot;\n&quot;);
      printf(&quot;--------------------------------------------------\n&quot;);
      printf(&quot;--------------------------------------------------\n&quot;);
      printf(&quot;\n&quot;);
      
      
      // Total rainfall
      for (i=0; i &lt; size_of_array; i++)
      {
          sum = sum + values[i];
      }
      
      printf(&quot;Sum of all rainfall values -&gt; %.2f mm\n&quot;, sum);
      printf(&quot;\n&quot;);
      
      // Average rainfall
      avg = sum / size_of_array;
      
      printf(&quot;Average rainfall value -&gt; %.2f mm\n&quot;, avg);
      printf(&quot;\n&quot;);
      printf(&quot;--------------------------------------------------\n&quot;);
      printf(&quot;--------------------------------------------------\n&quot;);
      printf(&quot;\n&quot;);
      
      // Largest and Lowest rainfall values
      largest=values[0];
      for(i=0; i &lt; size_of_array; i++)
      {
          if(values[i]&gt;largest)
          largest=values[i];
      }
      lowest=values[0];
      
      for(i=0; i &lt; size_of_array; i++)
      {
          if(values[i]&lt;lowest)
          lowest=values[i];
      }
      
      printf(&quot;The highest rainfall value -&gt; %.2f mm\n&quot;, largest);
      printf(&quot;\n&quot;);
      printf(&quot;The lowest rainfall value -&gt; %.2f mm\n&quot;, lowest);
      printf(&quot;\n&quot;);
      
      /* for (i=0; i &lt; 12; i++)
      {
          sum1 = sum1 + values[i];
      }
      
      printf(&quot;Total rainfall for 1958 -&gt; %.2f mm\n&quot;, sum1); */
      
      return 0;
  }
  </code></pre>