DEV Community

Deva I
Deva I

Posted on

In Array Program Using Any Student Marks To Find: 1.Fail Count. 2.Total Marks. 3.Average. 4.If the student fails Print "No grade" or Pass print "Grade".

1.Fail Count.
2.Total Marks.
3.Average.
4.If the student fails Print "No grade" or Pass print "Grade" based on Average.

1)PROGRAM:

STEPS:

Step 1: Declare a marks in an array.Notation is const marks[marks]

Step 2:We wanna fail count,total, and average.so declare a global variable named let.we don't know about the fail count,total and average so, declare let fail=0,total=0,average=0.

Step 3: Then declare i=0.because the first element of array is index 0.

Step 4:Next write the while loop(i<5). because the array have five elements and index starting 0 to 4.

Step 5:Then declare the if(marks[i]<35)

Step 6:If the condition is true increase the fail count.

Step 7: Increment the value of i

Step 8:Print the fail count out of the while loop.

Step 9:Then again open the If statement to give (fail>0).

Step 10:If the condition is true,print No grade.

Step 11:Else again declare i=0.because in the previous we declared i, is fails and breaks the while loop because i=5 is (i<5).false.Now i value is 5.so again redeclare i or give another variable names like j,k.

Step 12:Write a new while loop give condition of while(i<5)

Step 13:Then give total = total + marks[i].

Step 14:Next increment the value of i.

Step 15:Out of while loop print total.

Step 16:Then find average.so give average= total/5.because we have 5 variables.

Step 17:Then write if condition student have no fail count if (fail==0).

Step 18:if (average >=90)
Print Grade A

Step 19: else if (average >80 && average < 90)
Print Grade B

Step 20: else if (average >70 && average < 80)
Print Grade C

Step 21:else if (average >50 && average < 70)
Print Grade D

Step 22:else
Print Grade E

WORKING:

1.We wanna fail count so declare fail count is 0.

2.Then check the while condition:
i = 0
While(0<5).True
i = 1
While(1<5).True
i = 2
While(2<5).True
i = 3
While(3<5).True
i = 4
While(4<5).True
i = 5
While(5<5).false.loop stop

3.Next check the if condition:

Index 0=80
if(marks[80]<35).false

Index 1=98
if(marks[98]<35).false

Index 2=89
if(marks[89]<35).false

Index 3=33
if(marks[33]<35).true

Index 4=100
if(marks[100]<35).false

4.If the condition is true fail count is increase.In the above condition index 0.1,2,4 is false. so fail count not increase.Index 3 is true,then fail count increase.Fail count is 1.

5.Finally when the while loop fails it prints the fail count.

6.Next fail count is > 0,Print No grade.(fail>0)

 ◾ Fail is 1> 0.true
  So,in this program not runs else part.print No grade. 
Enter fullscreen mode Exit fullscreen mode

7.If the above if condition is fails the else part will runs.

OUTPUT:

2)PROGRAM:
✓ In this program little vary from above program. one array value is changed. Index 3 value 89 changed instead of 33.

✓ Otherwise same steps like above program.


WORKING:
1.Same working like above program in the No grade step.In this program fail count is 0.So the else part runs.

2.If the above if condition is fails so the else part runs.so create new while loop and give
i = 0 and then while (i<5)

3.Find total,so total = total + marks[i].

◾ Total=0+80 =80.total is 80

◾ Total=80+98 =178.total is 178

◾ Total=178+89 =267.total is 267

◾ Total=267+86 =353.total is 353

◾ Total=353+100 =453.
total is 453.

4.Increment the value of i

5.Then print total.

6.Next find average using Math.floor it's give first value of quotient.So give average = Math.floor(total/5)

◾Average = 453/5=90.6
We use Math.floor,so the average is 90.

8.if (fail == 0).fail count
is 0.true

7.The average is (average >= 90).
(90 = 90)

8.So, print the grade A.

OUTPUT:

Top comments (0)