0% found this document useful (0 votes)
19 views7 pages

Chapter 05 - Operators

Chapter 5 of the C Programming Language course focuses on Arithmetic Operators, which include addition, subtraction, multiplication, and division. It distinguishes between unary operators, which operate on a single operand, and binary operators, which require two operands. The chapter also includes a practical programming exercise involving calculations based on item prices and quantities.

Uploaded by

youhounx
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

Chapter 05 - Operators

Chapter 5 of the C Programming Language course focuses on Arithmetic Operators, which include addition, subtraction, multiplication, and division. It distinguishes between unary operators, which operate on a single operand, and binary operators, which require two operands. The chapter also includes a practical programming exercise involving calculations based on item prices and quantities.

Uploaded by

youhounx
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like