0% found this document useful (0 votes)
44 views

Algorithm Format

The first algorithm accepts 20 numbers as input, sets a product variable to 1, uses a for loop to multiply each input number by the product variable, and prints the final product. The second algorithm uses a for loop to count the number of zero and non-zero numbers among 45 inputs. The third algorithm uses a while loop to count the positive and negative numbers among a set of integer inputs until a zero is entered. The fourth algorithm uses a while loop to find the largest number entered among a set of inputs, stopping when 99 is entered.

Uploaded by

Freakshow38
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)
44 views

Algorithm Format

The first algorithm accepts 20 numbers as input, sets a product variable to 1, uses a for loop to multiply each input number by the product variable, and prints the final product. The second algorithm uses a for loop to count the number of zero and non-zero numbers among 45 inputs. The third algorithm uses a while loop to count the positive and negative numbers among a set of integer inputs until a zero is entered. The fourth algorithm uses a while loop to find the largest number entered among a set of inputs, stopping when 99 is entered.

Uploaded by

Freakshow38
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/ 4

Algorithms

First Step: Start

Prompt : Print/Output/Write “Prompt Instruction”

Input : Read variable_name

Processing:

 Assignment Statement : set variable_name = value


 Calculation : set variable_name = formula
 Selection type statement:
 if (condition) then
statement_block
endif
 if (condition_1) then
statement_block_1

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

 for variable_name = start_value to stop_value do


statement_block

endfor

 repeat
statement_block

until (condition)

Last Step: Stop


Exercise 1

Write an algorithm for the following:

a) A program that accepts 20 numbers and finds their product.

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

You might also like