Faculty of Engineering
Department of Information Technology Engineering
Chapter 5:
Operators
Lecturer: Toem Theara Course: C Programming Language
1. Arithmetic Operators
The Arithmetic Operators, Operators that perform addition (+), subtraction (-), multiplication (*),
and division (/) are the workhorses of many programming languages, including C.
In C, arithmetic operators are used to do math. They come in two main types:
Unary Binary
Additive Multiplicative
+ (Unary Plus) * (Multiplication)
+ (Addition) / (Division)
- (Unary Minus) - (Subtraction) % (Remainder)
Course: C Programming Language Chapter 5: Operators
1. Arithmetic Operators
The Arithmetic Operators, Operators that perform addition (+), subtraction (-), multiplication (*),
and division (/) are the workhorses of many programming languages, including C.
q Unary operators
A unary operator is an operator that works with only one operand (one value/variable).
• +x → unary plus (doesn’t change the value, just shows it’s positive)
• -x → unary minus (changes the sign)
📝 Example: Unary minus (-)
Course: C Programming Language Chapter 5: Operators
1. Arithmetic Operators
The Arithmetic Operators, Operators that perform addition (+), subtraction (-), multiplication (*),
and division (/) are the workhorses of many programming languages, including C.
q Binary operators
Binary means the operator needs two values: one on the left and one on the right.
• a + b → addition
• a - b → subtraction
📝 Example:
Course: C Programming Language Chapter 5: Operators
1. Arithmetic Operators
The Arithmetic Operators, Operators that perform addition (+), subtraction (-), multiplication (*),
and division (/) are the workhorses of many programming languages, including C.
📝 Example:
Course: C Programming Language Chapter 5: Operators
1. Arithmetic Operators
💻Practice
Problem: A customer buys some items in a shop.
⚙ Write a C program that:
1. Inputs
• price of 1 item (price)
• number of items (qty)
• money paid (paid)
2. Calculates and prints
• total = price * qty
• change = paid - total
• bonusCandy = change / 1000 (how many 1000-riel candies can be
given)
• remaining = change % 1000 (money left after giving candies)
Course: C Programming Language Chapter 5: Operators
3. Variables
Thank you!
Course: C Programming Language Chapter 4: Formatted Input/Output