Algorithm Format
Algorithm Format
Processing:
else
statement_block_2
endif
if (condition_1) then
statement_block_1
else
if (condition_2) then
statement_block_2
else
statement_block_3
endif
endif
Loops
while (condition_1) do
statement_block
endwhile
endfor
repeat
statement_block
until (condition)
Step 1: Start
Step 2: Set product = 1
Step 3: For i = 1 to 20 do
Step 4: Read num
Step 5: Set product = product * num
Step 6: Endfor
Step 8: Print “The product of 20 numbers is “, product
Step 9: Stop
b) A program that accepts 45 numbers and finds the number of zeroes and non-zeroes in them.
Step 1: Start
Step 2: For i = 1 to 45
Step 3: Read num
Step 4: If (num = 0) then
Set zero_count = zero_count + 1
Else
If (num <> 0) then
Set non_zero_count = non_zero_count + 1
Step 5: Endif
Step 6: Endif
Step 7: Endfor
Step 8: Print “Number of zeros: ”, non_zero_count
Step 9: Print “Number of non-zeroes: ”, non_zero_count
Step 10: Stop
c) A program that accepts a set of integers and find the number of positive and negative
numbers.
Step 1: Start
Step 2: While (num <> 0) do
Step 3: Read num
Step 4: If (num > 0) then
Set Pos_count = pos_count + 1
Else
If (num < 0) then
Set Neg_count = neg_count + 1
Endif
Endif
StepEndwhile
Print “Number of positive numbers: ”, pos_count
Print “ Number of negative numbers: “, neg_count
Stop
d) A program that accepts a set of numbers and find the largest among them.
“The program stops when the user enters 99 as the number”
Start
Write “Enter a number or 99 to end the program”
Set largest = 0
While (num <> 99) do
If (num > largest) then
Set largest = num
Endif
Endwhile
Print largest, “ is the largest number entered”
Stop