Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ANDHRA PRADESH
Name : T.Sudhakar
Designation : Lecturer in Computer Engg.
Institute : S.S.Govt. Polytechnic, Zaheerabad
Branch : Computer Engg.
Year/Semester : III Semester
Subject : UNIX & C
Code : CM-304
Major Topic : Programming Constructs
Sub-Topic : Arithmetic Operators & Its Evaluation
Duration : 50 Min
Teaching Aids : PPT, Animations
CM304.33 1
Objectives
On completion of this period you would be able to
know
Operator and its classification
Arithmetic Operators
Expression
Arithmetic Expression
Evaluation of Arithmetic Expression
CM304.33 2
Recap
1.What is a Variable?
2.What is Constant?
CM304.33 3
Operators
Symbol that tells the computer to perform
certain mathematical and logical manipulations
Classification of C Operators
Arithmetic Operators
Relational Operators
Logical operators
Assignment Operators
Increment and decrement Operators
Conditional Operators
CM304.33 4
Arithmetic Operators
These are used for mathematical calculations.
These can operate on any built in data type.
+ Addition or unary plus
- Subtraction or unary minus
* Multiplication
/ Division
% Modulo division
(it gives the remainder after integer division)
CM304.33 5
Examples
Here a and b are variables and are known as
operands
a+b
a–b
a*b
a/b
a%b
CM304.33 6
Integer Arithmetic
CM304.33 7
Integer Arithmetic
a – b = 10
a + b = 18
a * b = 56
a/b=3 (Decimal part truncated)
a%b=2 ( Remainder of division)
CM304.33 8
Modulo division (%)
Produces remainder of integer division.
It can be used only on integer type of data.
The sign of the result is always the sign of
the first operand.
Example:- 14 % -3 = 2
-14 % 3 = -2
-14 %-3 = -2
CM304.33 9
Real Arithmetic
Arithmetic Operation involves only floating or Real
operand.
% operator can not be used with real operands.
Examples:-
If x, y, z are floats then we will have
x = 6.0 / 7.0 = 0.857143
y = 1.0 / 3.0 = 0.857143
z = 3.5 + 6.0 = 9.5
CM304.33 10
Mixed mode Arithmetic
Arithmetic Operation involves one real operand
and one integer operand.
In this case, real operation is performed, the
result is always the real number.
Examples:-
15 / 10.0 = 1.5
15 / 10 = 1
15 / 10.0 = 1.5
CM304.33 11
Expression
Combination of constants, variables and
operators arranged as per the syntax of the
language.
Arithmetic Expression
Combination of constants and variables
connected by arithmetic operators.
CM304.33 12
Evaluation of Arithmetic Expression
CM304.33 15
Contd..
((2 + 3) * 4 – 5 – 6 + 2) / 3 + 4 % 3
(5 * 4 – 5 – 6 + 2) / 3 + 4 % 3
(20 – 5 – 6 + 2) / 3 + 4 % 3
(15 – 6 + 2) / 3 + 4 % 3
(9 + 2) / 3 + 4 % 3
11 / 3 + 4 % 3
3+4%3
3+1
4
CM304.33 16
Summary
CM304.33 17
Quiz
a) 28 b) 24
c) 6 d) 9
CM304.33 18
Quiz
a) 28 b) 24
c) 6 d) 9
CM304.33 19
Quiz
a) 28.5 b) 24
c) 6.0 d) 23.0
CM304.33 20
Quiz
a) 28.5 b) 24
c) 6.0 d) 23.0
CM304.33 21
Frequently Asked Questions
CM304.33 22