DEV Community

Madhavan G
Madhavan G

Posted on

Student Performance Evaluation Using Arrays and Loops.

PROGRAM:
const marks=[96,85,64,94,100];
let i=0;
let failCount=0;
let total=0;
let average=0;
let j=0;
while(i if(marks[i]<35){
fcount++;
}
i++
}
console.log("FailCount",failCount);
if(failCount>0){
console.log("no grade")
}
else{
j=0;
while(j total+=marks[j];
j++;
}
}
console.log("Total",total);
average=Math.floor(total/marks.length);
console.log("Average",average);
if(failCount==0){
if(average>=90){
console.log("grade A");
}
else if(average>=80){
console.log("grade B");
}
else if(average>=70 ){
console.log("grade C");
}
else if(average>=60){
console.log("grade D");
}
else{
console.log("grade E")
}
}
OUTPUT:
FailCount 0
Total 439
Average 87
grade B

FLOWCHART:

EXPLANATION:
Step 1.Assigning vaiables like marks=[96,85,64,94,100],i=0,j=0,total=0,average=0,failCount=0.

Step 2.It checks the while loop condition:
i < marks.length →0 < 5 →true
So, the loop starts.

Step 3.Check marks[i] < 35 → marks[0] = 96 → not less than 35
So, failCount remains 0
Increment i → i = 1.

Step 4.Check 1 < 5 → true
marks[1] = 85 → not less than 35
failCount = 0
Increment i = 2

Step 5.
Check 2 < 5 → true
marks[2] = 64 → not less than 35
failCount = 0
Increment i = 3

Step 6.
Check 3 < 5 → true
marks[3] = 94 → not less than 35
failCount = 0
Increment i = 4

Step 7.
Check 4 < 5 → true
marks[4] = 100 → not less than 35
failCount = 0
Increment i = 5

Step 8.
Check 5 < 5 → false
Exit the loop.

Step 9.
Print:
FailCount 0

Step 10.
Check condition: failCount > 0 → 0 > 0 → false
So, go to else block.

Step 11.
Initialize j = 0
Check j < 5 → 0 < 5 → true

Step 12.
Add marks[0] = 96 → total = 96
Increment j = 1

Step 13.
Check 1 < 5 → true
Add marks[1] = 85 → total = 181
Increment j = 2

Step 14.
Check 2 < 5 → true
Add marks[2] = 64 → total = 245
Increment j = 3

Step 15.
Check 3 < 5 → true
Add marks[3] = 94 → total = 339
Increment j = 4

Step 16.
Check 4 < 5 → true
Add marks[4] = 100 → total = 439
Increment j = 5

Step 17.
Check 5 < 5 → false
Exit loop.

Step 18.
Print:
Total 439

Step 19.
Calculate average:
average = Math.floor(439 / 5) = 87
(Here Math.floor used to avoid decimal values)

Step 20.
Print:
Average 87

Step 21.
Check failCount == 0 → true
So grading starts.

Step 22.
Check conditions:
87 >= 90 → false
87 >= 80 → true
So:
grade B

Final Output (For Given Input):
FailCount 0
Total 439
Average 87
grade B
=== Code Execution Successful ===

Top comments (0)