Page 102 - 2502_Pakistan-kifayat_C-6
P. 102
CONVERTING AN ALGORITHM INTO A PROGRAM
Converting an algorithm into a program involves translating the step-by-step instructions from the
algorithm into actual code that can be executed by a computer. The process typically requires the use
of a specific programming language and syntax.
The steps to convert an algorithm into a program are as follows:
Step 1: Understand the Algorithm
The algorithm gives instructions for summing up all elements in a list by iterating through each element
and adding it to a variable sum.
Step 2: Identify Variables and Inputs
List of numbers: A collection of numbers to find the sum from.
Sum: A variable to store the running total of the sum.
The program should be able to take any list of numbers and return their sum.
The following table shows the step-by-step conversion of an algorithm into a program:
Algorithm Program Code
Scenario: Sum of Two Numbers Scenario: Sum of Two Numbers
Step 1: Start. Step 1: START
Step 2: Input two numbers (say num1 and Step 2:
num2). PRINT "Enter the first number:"
READ num1
PRINT "Enter the second number:"
READ num2
Step 3: Add the two numbers: sum = num1 + Step 3: sum = num1 + num2
num2.
Step 4: Display the result (sum). Step 4:
PRINT "The sum of the two numbers is: ", sum
Step 5: Stop. Step 5: STOP
100 Premium Edition-VI

