Unit 2 - Imperative-Updated
Unit 2 - Imperative-Updated
PROGRAMMIN
G
PARADIGM
Topics
■ Program state, instructions to change the program state
PL / I to
Algol to PL /I COBOL to PL/I LISP to PL/I
FORTR
• Block • Subprograms
AN • File • Dynamic
structur • Formatted IO manipulation storage
e • Record allocatio
• Control n
statement • Linked
s structure
• Recursion s
OVERVIEW
■ In imperative a name may be
assigned to a value
programming, and later reassigned to
another value.
■ The of names and the associated in
values and the location of
collection control the
program constitute the state.
■ The state is a model of storage
whichis
logical an association between memory locations
and values.
■ A program in execution generates a sequence of
states.
■ The transition from one state to next is
the determined by assignment operations and sequencing
commands.
Highlights on
■ Assignment, ■ Imperative language
# Imperative
DEMO
An algorithm to add two
entered
numbersby 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