slide 06 - operators and expressions
TRANSCRIPT
![Page 1: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/1.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 1/49
Computer Science Department FTSM
Operators andExpressions
Knowledge:
Know the types of basic arithmetic operators and their order of precedence
Skill:
Develop skills in computer arithmetic
![Page 2: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/2.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 2/49
TK1913-C Programming 2
We use arithmetic expressions to solve
most programming problems
Arithmetic expressions comprise of
operators and operands
There are rules for writing andevaluating arithmetic expressions
Introduction
![Page 3: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/3.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 3/49
TK1913-C Programming 3
Operator and Operand
Example:
W + Z
Operand
Operator
Operand
What are operator and operand?
![Page 4: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/4.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 4/49
TK1913-C Programming 4
Example:
Operator and OperandWhich is which?
A / B
Operator ??
Operand??
![Page 5: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/5.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 5/49
![Page 6: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/6.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 6/49
TK1913-C Programming 6
Basic Arithmetic Operators Multiplication, addition and subtraction are
the simplest to use
Division is easy, but some precautions need to
be taken
Modulus is the one that normally confuses
novices
So, let’s study in detail the Division and Modulus
![Page 7: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/7.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 7/49
TK1913-C Programming 7
DivisionExample:
W / Z
Floating Division
W or Z or both are
floats
Integer Division
W and Z are integers
![Page 8: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/8.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 8/49
TK1913-C Programming 8
Example:Integer Division
8 / 2 = 4
an integer
an integer
the result isalso an integer
![Page 9: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/9.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 9/49
TK1913-C Programming 9
Example:Integer Division
12 / 5 = 2
an integer
an integer
the result isalso an integer
![Page 10: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/10.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 10/49
TK1913-C Programming 10
Example:Floating Division
12.0 / 5 = 2
a float
an integer
the result is a
float
![Page 11: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/11.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 11/49
TK1913-C Programming 11
What will be the answer
if an integer is dividedby 0? How about if one
of the operands is a
negative integer?
Something to ponder …
![Page 12: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/12.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 12/49
TK1913-C Programming 12
Modulus
It returns the remainder that occurs
after performing the division of 2
operands
Rule: Operands must be integers
![Page 13: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/13.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 13/49
TK1913-C Programming 13
Example:
Modulus
12 % 5 = 2
an integer
an integer
the result is theremainder of 12/5
125
2
102
remainderresult
![Page 14: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/14.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 14/49
TK1913-C Programming 14
Example:
Modulus
7 % 3 = 1
an integer
an integer
73
2
61
remainderresult
the result is theremainder of 7/3
![Page 15: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/15.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 15/49
TK1913-C Programming 15
Example:
Modulus
12.0 % 3 = ??
a float
an integer
INVALID!
![Page 16: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/16.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 16/49
TK1913-C Programming 16
The earlier expressions
contain only oneoperator at a time. What
if the expression
contains more than one
operator?
Something to ponder …
![Page 17: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/17.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 17/49
TK1913-C Programming 17
An expression may contain 2 or more
arithmetic operators
Main issue:
ORDER OF PRECEDENCE
Arithmetic Expression
![Page 18: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/18.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 18/49
TK1913-C Programming 18
Examples:
5 + 6
5 + 6 * 2
2.5 + 6 – 2 * 2
12 / 6.0 – 2 * 2
= 11
= 22 or 17?
= ??
= ??
= 17
Arithmetic Expression
![Page 19: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/19.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 19/49
TK1913-C Programming 19
Arithmetic ExpressionOrder of Precedence:
High: * / %
Low: + -
All operators have a precedence level. High
precedence level operators are evaluated beforelower ones. Operators of the same precedence levelare evaluated from left to right
![Page 20: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/20.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 20/49
![Page 21: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/21.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 21/49
TK1913-C Programming 21
Example:
Try it!
12 + 6.0 – 2 * 2 = ??
What’s the answer??
![Page 22: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/22.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 22/49
TK1913-C Programming 22
Arithmetic Expression
All expressions in parentheses (brackets) must
be evaluated prior to values outside brackets
Nested parenthesized expressions must be
evaluated from the inside out, with the
innermost expression evaluated first
Example:
( 9 – ( 3 + 2 ) ) * 3 = ??
![Page 23: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/23.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 23/49
TK1913-C Programming 23
Arithmetic Expression
Example:
( 9 – ( 3 + 2 ) ) * 3 = ?? – 54 12( 9 – ( 3 + 2 ) ) * 3 = 12
![Page 24: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/24.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 24/49
TK1913-C Programming 24
Assignment Statement
There are 3 types of assignment:
Simple
Multiple
Shorthand
![Page 25: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/25.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 25/49
Buying price:
Buying price: 10 00
Buying price: 10 00
Buying price: 10 00
Buying price: 10 00
Buying price: 10.00
![Page 26: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/26.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 26/49
TK1913-C Programming 26
Simple AssignmentExample:
#include <stdio.h>
void main( ) {
float price, discount, total;
printf(“Buying price : “);
scanf(“%f”, &price);
printf(“\nDiscount rate : “);
scanf(“%f”, &discount);
total = price – (price * discount);printf(“\nFor buying price RM%.2f and discount rate %.2f\n”,
price, discount);
printf(“The total price is RM%.2f \n”, total);
}
Buying price: _
discount ??
price ??
total ??
Buying price: 10.00
_
10.00
Buying price: 10.00
Discount rate: _
Buying price: 10.00
Discount rate: 0.25
_
0.25
7.50
Buying price: 10.00
Discount rate: 0.25
For buying price RM10.00 and discount rate 0.25
_
Buying price: 10.00
Discount rate: 0.25
For buying price RM10.00 and discount rate 0.25
The total price is RM7.50
_
![Page 27: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/27.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 27/49
TK1913-C Programming 27
Syntax:
variable = variable = expression ;
Multiple Assignment
Don’t forget the semicolon !!
![Page 28: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/28.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 28/49
![Page 29: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/29.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 29/49
TK1913-C Programming 29
Shorthand Assignment
Syntax:
variableX = variableX op expression ;
variableX op = expression;
![Page 30: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/30.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 30/49
TK1913-C Programming 30
Whenever the expression on the right contains the
variable on the left (to which the value is assigned)
Example:
num = num + 5;
num 15
15 + 5
20
20
Shorthand Assignment
![Page 31: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/31.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 31/49
TK1913-C Programming 31
Expressions can also be stated using shorthand
assignment operators
Example:num += 5; similar to num = num + 5
shorthand assignment operator
Shorthand Assignment
Shorthand assignment operators have the lowest
order of precedence – the last one to be evaluated
![Page 32: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/32.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 32/49
TK1913-C Programming 32
Operation Examples of
expression
Description
+= num += 5; num = num + 5;
-= num -= 5; num = num – 5;
*= num *= 5; num = num * 5;
/= num /= 5; num = num / 5;
%= num %= 5; num = num % 5;
Shorthand Assignment
![Page 33: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/33.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 33/49
TK1913-C Programming 33
Example:
pay += hour * rate * 2
pay + (8 * 5.00 * 2)
pay 100.00
hour 8
rate 5.00
similar to pay = pay + (hour * rate * 2)
pay + (hour * rate * 2)
100.00 + 80.00
180.00
180.00
Shorthand Assignment
![Page 34: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/34.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 34/49
TK1913-C Programming 34
Assignment by Value
Every assignment expression has a value
Example:
Expression 1: a = 1;
Expression 2: x = y = 0;
Expression 3: p = 12;
p = 0;
Example:
int a, x, y, p;
Line 1: a=1;
Line 2: x = y = 0;
Line 3: p = 12;Line 4: p = p +3;
Line 5: q = p = p + x;
![Page 35: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/35.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 35/49
TK1913-C Programming 35
Relational OperatorsOperation Description Examples
of
Expression
Value
< Less than 6 < 9 1 (true)<= Less than or equal to 5 <= 5 1 (true)
> Greater than 2 > 6 0 (false)
>= Greater than or equal to 9 >= 5 1 (true)
== Equal to 7 == 5 0 (false)
!= Not equal to 6 != 5 1 (true)
![Page 36: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/36.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 36/49
![Page 37: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/37.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 37/49
TK1913-C Programming 37
Compound Statement
Arithmetic, relational and mantic operators can be
integrated/combined in one expression
Example:
! ( c > a )a 2
b 5
c 15
d 17! ( 1 )
! ( 15 > 2 )
0
![Page 38: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/38.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 38/49
TK1913-C Programming 38
Example:
(a >= 1) && (b == 5)
a 2
b 5
c 15
d 17
( 2 >= 1 ) && ( b == 5 )
Compound Statement
1 && ( b == 5 )
1 && ( 5 == 5 )
1 && 1
1
![Page 39: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/39.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 39/49
TK1913-C Programming 39
Example:
(c >= ( b * 3 ) ) || (a == 3)
a 2
b 5
c 15
d 17
( c >= ( 5 * 3 ) ) || ( a == 3)
Compound Statement
1 || ( a == 3 )
1 || ( 2 == 3 )
1 || 0
( 15 >= 15 ) || ( a == 3)
1
![Page 40: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/40.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 40/49
TK1913-C Programming 40
Example:
! ( ( a < b ) || ( c > d ) )
a 2
b 5
c 15
d 17
! ( ( 2 < 5 ) || ( c > d ) )
Compound Statement
! ( 1 || ( 15 > 17 ) )
! ( 1 || 0 )
! 1
! ( 1 || ( c > d ) )
0
![Page 41: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/41.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 41/49
TK1913-C Programming 41
Increment and DecrementThis operation contains only one operand, that is,the operand which value will be incremented/
decremented
Symbol Description Examples of
Expression
Description
++ Increment
operand by 1
i++ i = i + 1
-- Decrement
operand by 1
i-- i = i – 1
![Page 42: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/42.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 42/49
TK1913-C Programming 42
Key-in a number: _Key-in a number: 26
_
Increment and DecrementExample:
int num;
printf(“Key-in a number: “);
scanf(“%d”, &num); printf(“Value before being incremented: %d\n”, num);
num++;
printf(“Value after being incremented: %d”, num);
num ??
Key-in a number: 26
Value before being incremented: 26
_
2627
Key-in a number: 26
Value before being incremented: 26
Value after being incremented: 27 _
![Page 43: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/43.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 43/49
TK1913-C Programming 43
Prefix and PostfixIncrement and Decrement operators can be either in prefix or
postfix forms
Expression Description
i++ Value of i is incremented after being used in the
expression
++i Value of i is incremented before being used in the
expression
i-- Value of i is decremented after being used in theexpression
--i Value of i is decremented before being used in the
expression
![Page 44: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/44.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 44/49
TK1913-C Programming 44
Example:
j = i++ - 2
i 5
similar to
j = i – 2;
i = i + 1;
Prefix and Postfix
j ??3
6
![Page 45: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/45.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 45/49
TK1913-C Programming 45
Example:
j = ++i - 2
i 5
similar to
i = i + 1;
j = i – 2;
Prefix and Postfix
j ??4
6
![Page 46: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/46.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 46/49
TK1913-C Programming 46
Example:int x = 10;
float y;
y = (float) x;
Coersion
( float ) 10
10.000000
x 10
y ??10.000000
Coersion is used to compute a value that is equivalent
to its operand’s value (based on the stated data type)
![Page 47: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/47.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 47/49
TK1913-C Programming 47
Example:
int total, number;
float average;
…
average = total / number;
Coersion
15 / 2
7
total 15
number 2
average ??7.000000
![Page 48: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/48.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 48/49
TK1913-C Programming 48
Example:
int total, number;
float average;
…
average = (float) total / number;
Coersion
15.000000 / 2
7.500000
total 15
number 2
average ??7.500000
![Page 49: Slide 06 - Operators and Expressions](https://reader030.vdocument.in/reader030/viewer/2022021317/577cc3811a28aba711962e37/html5/thumbnails/49.jpg)
8/10/2019 Slide 06 - Operators and Expressions
http://slidepdf.com/reader/full/slide-06-operators-and-expressions 49/49
End of Lecture 6
Yes !! That’s all?What’s next???
CONTROL STRUCTURE:
SELECTION on the way …