[go: up one dir, main page]

0% found this document useful (0 votes)
13 views2 pages

Assignment 5

The document outlines an algorithm for calculating the sum of positive integers entered by the user, including variable declarations and step-by-step instructions. It also includes a flowchart representation of the algorithm's process. Additionally, each line of the algorithm is explained for clarity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Assignment 5

The document outlines an algorithm for calculating the sum of positive integers entered by the user, including variable declarations and step-by-step instructions. It also includes a flowchart representation of the algorithm's process. Additionally, each line of the algorithm is explained for clarity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

ASSIGNMENT 5

1a. Algorithm to Find the Sum of Positive Integers Entered by the User

Variable declarations:
num, sum are integer types

Step 1: Initialize sum ← 0


Step 2: Prompt user to enter a number
Step 3: Read num
Step 4: WHILE (num > 0) DO
sum ← sum + num
Prompt user to enter another number
Read num
END WHILE
Step 5: Print sum
Step 6: Stop

1b. Flowchart
The flowchart is shown below:

Start
Start

Sum 0

Prompt for number

Read number

No
Num > 0?
Yes

Sum Sum+Num

Prompt for number

Read Number

Print Sum
Stop
1c. Explanation of each line of Algorithm
 Variable declarations: Define the necessary variables to store user input (num) and the
cumulative total (sum).
 Step 1: Initialize sum to zero to begin accumulation from zero.
 Step 2: Ask the user to input a number.
 Step 3: Take the user’s input and store it in num.
 Step 4: Begin a loop that checks if the number is greater than 0. If true, add the number
to sum, ask the user to enter another number, and repeat.
 Step 5: After exiting the loop, print the total sum.
 Step 6: End the algorithm.

You might also like