MENU
Question -

Write an algorithm to compute the sum of odd and even numbers up to N.



Answer -

The algorithm as :

Step 1: Start.
Step 2 : Input N.
Step 3 : sume = 0.
Step 4 : sumo = 0.
Step 5 : ctr = 1.
Step 6 : while (ctr < = N).
If (ctr mod 2 = 0)
sume = sume + ctr
else
sumo = sumo + ctr.
Step 7: Print “sum of even number is” sume.
Step 8 : Print “sum of odd number is” sumo.
Step 9: End.

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×