title: Getting the Average,Min, and Max of numbers in 2D array
body: <p>I have a problem with getting the min,max, and average of an elements of 2D array.</p>
  
  <p>I have a 2D array which contains Students and Grades. </p>
  
  <p>I am generating the grades with rand. For example When I enter 2,2 it prints me out </p>
  
  <pre><code>Courses : 01   02   Average   Min   Max
      ID   
      01     8   50     29
      02    74   59     29
  </code></pre>
  
  <p>, My average function takes the first ones average and doesnt take the others average. </p>
  
  <p>Here is my code ;</p>
  
  <pre><code>int A[30][30];
  
  int findAverage(int noOfStudents ,int noOfGrades ){
  
      float sum,average;
  
  
  
  
      for (int i = 0 ; i &lt; noOfGrades ; i++) {
          for (int j = 0; j&lt;noOfStudents; j++) {
  
          sum += A[i][j];
  
          }
          average = sum / noOfGrades;
         // cout &lt;&lt; "   " &lt;&lt; format(average);
          sum = 0;
          return format(average);
  
      }
  </code></pre>
  
  <p>and here how I use it</p>
  
  <pre><code>int main() {
  
      int noOfCourses , noOfStudents;
      cin &gt;&gt; noOfCourses &gt;&gt; noOfStudents;
      cout &lt;&lt; "Courses : " ;
  
      for (int i = 0; i &lt; noOfCourses; i++) {
          if (i+1 &gt;= 10) {
  
              cout &lt;&lt; i+1 &lt;&lt; "   ";
          }else{
              cout &lt;&lt;"0" &lt;&lt; i+1 &lt;&lt; "   ";
  
          }
      }
  
      cout &lt;&lt; "Average   Min   Max";
  
      for(int i=0; i&lt;noOfStudents; i++) {         //This loops on the rows.        
  
          for(int j=0; j&lt;noOfCourses; j++) {     //This loops on the columns
              A[i][j] = genGrade(); 
          }
      }
  
      cout &lt;&lt; "\n    ID   " &lt;&lt; endl;
  
      for(int i=0; i&lt;noOfStudents; i++) {  //This loops on the rows.
  
          if (i+1 &gt;= 10) {
  
              cout &lt;&lt;"    " &lt;&lt; i+1 &lt;&lt; "   ";
          }else{
              cout &lt;&lt;"    0" &lt;&lt; i+1 &lt;&lt; "   ";
  
          }
  
          //cout &lt;&lt;"    0" &lt;&lt; i+1 &lt;&lt; "   ";
  
          for(int j=0; j&lt;noOfCourses; j++) {  //This loops on the columns
  
  
              if (A[i][j] &gt;= 10 &amp;&amp; A[i][j] &lt;=99) {
  
                  cout &lt;&lt;" " &lt;&lt; A[i][j]  &lt;&lt; "  ";
              }
              if(A[i][j] &lt; 10) {
  
                  cout &lt;&lt;"  " &lt;&lt; A[i][j] &lt;&lt; "  ";
              }
              if (A[i][j] == 100) {
  
                  cout &lt;&lt; A[i][j] &lt;&lt; "  ";
              }
          }
          cout &lt;&lt;"   "&lt;&lt;findAverage(noOfStudents,noOfCourses);
          cout &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>What am I doing wrong ? Also How could I get the min,max of the per array?</p>