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<time.h>
#include<stdio.h>
#include<stdlib.h>
int main() {
int sum=0,fark,avg,imax;
int puan[10];
srand(time(NULL));
for(int i=0; i<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]>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<10;i++)
{
puan[i] += fark;
}
for(int i=0;i<10;i++)
{
if(puan[i]<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.