Program to generate numbers, finding average and largest values and rounding the largest to 100 As this code is not in English, I will explain it first:


Creates ten numbers in an array between 0 and 100 as student grades.
Calculates the largest number and average value of these ten numbers in the array.
100, the largest grade, is subtracted from the largest number in the array. (e.g 100-96=4)
New value (which is 4 in this case, explained in example above) is added to all numbers in the array. It's also printed just below average value and largest value.
New values in the array that are unable to surpass the average value are printed down below, which prints a sentence in Turkish that roughly translates to:

"%dth student with %d grade has failed the lesson by staying under the average value."





#include&lt;time.h&gt;
#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;

int main() {

int sum=0,fark,avg,imax;
int puan[10];
srand(time(NULL));
for(int i=0; i&lt;10; i++) 
{
    puan[i]=rand()%101;
    printf("%d. ogrencinin notu = %d ",i+1,puan[i]);
    printf("\n");
    if(i==0) 
    {
        imax=puan[i];
    }
    else if(puan[i]&gt;imax) 
        {
            imax=puan[i];
        }
    sum += puan[i];
}
avg=sum/10;
fark= 100 - imax;
printf("\nEn yuksek not = %d ve not ortalamasi %d.\n",imax,avg);
printf("Her ogrencinin notuna %d puan eklendi.\n",fark);
printf("\n");
for(int i=0;i&lt;10;i++) 
{
    puan[i] += fark;
}
for(int i=0;i&lt;10;i++) 
{
    if(puan[i]&lt;avg) 
    {
        printf("%d. ogrenci aldigi %d notuyla ortalamanin altinda kalarak dersten basarisiz olmustur.\n",i+1,puan[i]);
    }
}
return 0;
}


Can I shorten this code? Is there a shorter way to make it work in the same way? This was the best my friend and I could come up with.
Just a quick approach. It could be improved more. What you want is a way to reduce the two loops into one.

Some comments about the code: We initialized imax in order to reduce the if -else statement and also we combined the 2 foor loops in the end into one. What I would like to achieve even more is to reduce the final two for loops into one. But I think this is not possible for this case. But I might be wrong.

#include &lt;time.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int main() {
    int sum = 0, imax = 0;
    int puan[10];
    srand(time(NULL));
    for(int i=0; i&lt;10; i++)
    {
        puan[i]=rand()%101;
        printf("%d. ogrencinin notu = %d \n",i+1,puan[i]);
        if(puan[i]&gt;imax) 
        {
            imax=puan[i];
        }
        sum += puan[i];
    }
    float avg=sum/10.0f;
    int fark = 100 - imax;
    printf("\nEn yuksek not = %d ve not ortalamasi %f.\n",imax,avg);
    printf("Her ogrencinin notuna %d puan eklendi.\n\n",fark);
    for(int i=0;i&lt;10;i++)
    {
        puan[i] += fark;
        if(puan[i]&lt;avg) 
        {
                printf("%d. ogrenci aldigi %d notuyla ortalamanin altinda kalarak dersten basarisiz olmustur.\n",i+1,puan[i]);
        }
    }

    return 0;
}