Another example of an algorithm with repeating statements

Let’s take another example of an algorithm in which we will use repeating statements to write the flow of the algorithm.

Problem definition

Write an algorithm to add all numbers from 1 till 1000 which are multiples of 5. Print the final sum on the screen

See the algorithm below

Start
Step 1: Take a variable A
Step 2: Set A = 5
Step 3: Take a variable SUM
Step 4: Set SUM = 0
Step 5: If A > 1000 Goto Step 9
Step 6: Set SUM = SUM + A
Step 7: Set A = A + 5
Step 8: Goto Step 5
Step 9: Print the value of SUM
Stop

In this example you can see how Step 5 to Step 8 are repeating themselves. We are incrementing the value of A, adding it to the total sum, checking if A > 1000 or not and then repeating the steps.

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp