0% found this document useful (0 votes)
7 views1 page

Student Average Percentage Algorithm

The document outlines an algorithm for reading and analyzing student averages, specifically calculating the percentage of students in three average ranges: below 10, between 10 and 15, and 15 or above. It includes controlled input to ensure that the number of averages is between 1 and 100 and that each average is between 0 and 20, prompting the user to re-enter values if they are incorrect. Finally, it displays the calculated percentages based on the input data.

Uploaded by

soufiene
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Student Average Percentage Algorithm

The document outlines an algorithm for reading and analyzing student averages, specifically calculating the percentage of students in three average ranges: below 10, between 10 and 15, and 15 or above. It includes controlled input to ensure that the number of averages is between 1 and 100 and that each average is between 0 and 20, prompting the user to re-enter values if they are incorrect. Finally, it displays the calculated percentages based on the input data.

Uploaded by

soufiene
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Algorithmic I Ch 4 : Iterative structure – 10) Exercise 3 2023/2024

Exercise 3 : (Course)
Write an algorithm that reads n real values between 0 and 20 (which represent the averages of
n students with 0<n≤100) and displays :
• The percentage of students with an average < 10
• The percentage of students with an average ≥ 10 and < 15
• The percentage of students with an average ≥ 15
The algorithm must take into account incorrect entries (values < 0 and > 20). In this case, the
user is asked to re-enter the value until it is correct.

Solution :

Algorithm Statistics;
Variable
nb1, nb2, nb3, i, n : integer; x : real;
Begin
/*(1) Controlled reading of the number of averages n between 1 and 100*/
Repeat
Print(“Give the number of averages n>0 and <=100“);
Read(n);
Until (n>0 and n<=100);
/*(2) Initialize the three counters to 0*/
nb1 0; nb20; nb30;
/*(3) Repeat the treatment for traitement for each of the n averages*/
For i  1 to n step 1 do
/*(3.1) Controlled reading of an average*/
Repeat
Print(“Give the average n° “,i ,“ between 0 and 20 : “); Read(x);
Until (x>=0 and x<=20);
/*(3.2) Updating the three counters*/
If(x<10) then nb1nb1+1;
Else If (x>=15) then nb3nb3+1;
Else /*The average is between 10 and 15*/
nb2nb2+1;
EndIf;
EndIf;
EndFor;

/*(4) Calculate and display the three percentages*/


Print(“The percentage of students with an average < 10 is : “, nb1*100/n, “%“);
Print(“The percentage of students with an average ≥ 10 and < 15 is : “, nb2*100/n,
“%“);
Print(“The percentage of students with an average ≥ 15 is : “, nb3*100/n, “%“);
End

Page 1 sur 1

You might also like