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

Assignment Statement in Programming

The document discusses assignment statements and their use to assign values to variables. It provides examples of assignment statements and their interpretation. It also includes sample pseudocode to demonstrate calculating sums, products, averages from input values.

Uploaded by

Nathefa Layne
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Assignment Statement in Programming

The document discusses assignment statements and their use to assign values to variables. It provides examples of assignment statements and their interpretation. It also includes sample pseudocode to demonstrate calculating sums, products, averages from input values.

Uploaded by

Nathefa Layne
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

LESSON NOTES

ASSIGNMENT STATEMENT

Assignment statements are used to give initial value to variables and to change
the value assigned to a variable.

The assignment statement has two parts, the Lvalue and the Rvalue. The
Lvalue refers to the variable as the storage location where the Rvalue will be
stored. The Rvalue refers to a value, which may be the result of an expression
or the content of another variable. The arrow (🡨) is used as the assignment
operator.

Consider the following Assignment statement:

Days 🡨 28

Rate 🡨 500

This can be interpreted as follows, store the value 28 in the variable days and
500 in the variable rate.

Consider the following assignment statement:

Salary 🡨 Days * Rate

The Lvalue is “salary” on the left and the Rvalue is the expression on the right,
“days*rate”. The assignment can be interpreted as, multiply the value in the
variable days by the value in the variable rate and store the result in variable
salary.
BEGIN
READ A
READ B
READ C
C🡨A
A🡨B
B🡨C

Print A, B, C
END

What would be the printed result of the variables A, B and C if 2 is entered in A, 5 entered in
B and 4 entered in C.

1. Score 🡨 75
2. Sum 🡨 220
3. Value 🡨 Sum + Score
4. Sum 🡨 Score
5. Score 🡨 Value + Sum
6. Value 🡨 Sum + Score
Answer the following questions using the lines of codes above.

a. What is the value stored in value in line 3. _________


b. What is the value stored in sum in line 4. __________
c. What is the value stored in value in line 5. _________
d. What is the value stored in score in line 5. _________
e. What is the value stored in value in line 6. _________
f. What is the value stored in sum in line 6. __________

Use all three statements and complete the following questions:

Write a pseudocode algorithm to accept three numbers and find and print their sum.

We can analyze this question by finding out the Input, process and output, creating
what is called an IPO (Input, process, Output) table.
Based on the question we can arrive at the following IPO table.

INPUT PROCESS OUTPUT


Three numbers Calculate sum sum

START

Declare num1,num2,num3 as real

PRINT “Please enter three numbers”


READ num1, num2, num3

Sum 🡨 num1 + num2 + num3


PRINT “The sum of the three numbers is”, Sum

STOP

1. Write a pseudocode algorithm to read three numbers and find their products and
average and print the sum, average and product.

2. Write a pseudocode algorithm to calculate the cost of a product given the quantity and
the unit price. The cost, quantity and unit price must be printed

3. Write a pseudocode algorithm to accept the current year and the year a person was
born. Calculate and print the age of the person.

You might also like