Calculates the Average Score of Given Number of Scores in C I have started with C and I made this code and as the title suggests this program can calculate the average score of a given number of scores. Now my major concern is, is it more efficient to get the number of scores as a Command Line Argument or is the current approach better incase if sometime in the future someone designs a Interactive Front-End for it?
Also I am using the cs50 library I am not sure if it is allowed here please tell me if it's not so I'll keep that in mind in the future.
#include &lt;cs50.h&gt;
#include &lt;stdio.h&gt;
float average(int length, int array[]);

int main(void)

{
    int i, j;
    printf(&quot;This Program will Help you Compute the Average Score \n&quot;);         //Welcome Message
    int Total = get_int(&quot;How Many Scores do you wish to Use: &quot;);               //Asks User for How Many Scores
    int scores[Total];                                                         //Stores Scores in an Array
    for (i=0; i &lt; Total; i++)                                                  //A Loop to keep Asking for Scores
    {
        scores[i]=get_int(&quot;Enter Score %d \n&quot;, i+1);                           //i+1 is used as it would be better to start asking from Score 1 so that it avoids confusion
    }
    printf(&quot;The Average score is %f&quot;, average(Total, scores));
}

float average(int length, int array[])
  {  int sum = 0;
    for (int j=0; j &lt; length; j++)
    {
        sum += array[j];
    }
    return sum/(float)length;
  }
Reduce the number of loops
The most time-consuming part of your program is to loop through the array. Notice that you have done this twice, why can't you keep a track of the total sum while taking the input?
#include &lt;stdio.h&gt;  

float average(int sum,int number);

int main(void)
{
    int number_of_integers,number,sum = 0;
    printf(&quot;Enter the number of integers: &quot;);
    scanf(&quot;%d&quot;,&amp;number_of_integers);
    for(int i = 0;i &lt; number_of_integers;i++)
    {
        printf(&quot;Enter: &quot;);
        scanf(&quot;%d&quot;,&amp;number);
        sum+=number;
    }
    printf(&quot;Average = %d&quot;,average(sum,number_of_integers));
}

float average(int sum, int number)
{
    return sum/(float)number;
}

This reduces the number of loops from 2 into 1. And completely removes the need of having an array of integers. Making your program both memory efficient and fast.