Unit 2 - Imperative
Unit 2 - Imperative
PROGRAMMING
PARADIGM
Mrs. S. Niveditha
Assistant Professor (Sr. G)
Department of Computer Science and Engineering
SRMIST, Vadapalani Campus
Topics
■ Program state, instructions to change the program state
PL / I to
Algol to PL /I FORTRAN COBOL to PL/I LISP to PL/I
■ Command ■ State
■ Statement ■ Variables
■ Procedure ■ Instructions
# Imperative
DEMO
An algorithm to add two numbers
entered by user
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to
sum. sum←num1+num2
Step 5: Display sum
Step 6: Stop
Addition two numbers entered by user
An Algorithm to Get n number, print
the same and find Sum of n numbers
Step 1: Start
Step 2: Declare variable sum = 0.
Step 3: Get the value of limit “n”.
Step 4: If limit is reached, goto Step 7 else goto Step 5
Step 5: Get the number from user and add it to sum
Step 6: Goto Step 4
Step 7: If limit is reached, goto Step 9 else goto Step 8
Step 8: Print the numbers
Step 9: Goto Step 7
Step 9: Display sum
Step 10: Stop