Chapter 3 - COMPONEN OF PROGRAMMING II (CSC425)
Chapter 3 - COMPONEN OF PROGRAMMING II (CSC425)
Programming
(CSC425)
by
DR AFIZA ISMAIL
Faculty of Computer & Mathematical Sciences
UiTM MALAYSIA
Completing the Basics
Chapter 3
2
Contents
⚫ Assignment Operation
⚫ Mathematical Library Functions
⚫ Formatting Program Output
⚫ String Manipulation
variable = <variable|constant|expression>
⚫ Expression can be :
i. a constant
ii. another variable
iii. an arithmetic expression
iv. a function
⚫ Examples:
length = oldLength;
width = 50;
area = length * width;
moredata = true; //a boolean variable
⚫ Try to run :
- Exercise 4
- Exercise 8
- Exercise 13
+= -= /= %= *=
sum += 10;
March 17, 2024 CSC425 : INTRODUCTION TO COMPUTER 7
PROGRAMMING
Assignment Statement (cont.)
⚫ Example :
Expression Equivalent to
price = price * rate; price *= rate;
count = count + 3 count += 3
price *= rate + 1 price = price * (rate + 1)
but not
price = price * rate + 1
⚫ Example :
(See Exercise 15)
Expression Equivalent to
i = i + 1 ⚫ ++i (prefix increment operator)
If x = 5; and y = ++x;
After the second statement both x and y are 6
⚫ i++ (postfix increment operator)
If x = 5; and y = x++;
After the second statement y is 5 and x is 6
i = i - 1 --i
Assignment #1
Example :
sqrt(4.5) //square root of x
fabs(2.3 * 4.6) //absolute value |x|
tan(x) //tangent of x
floor(x) //largest interger <= x
⚫ String concatenation :
- joining two or more strings together to
become one long string.
Read totalScore
Read count
Display average
End