Lecture 6 – Operators in C (continued)
1. Binary
i.
Addition
+
ii.
Subtraction
-
iii.
Multiplication *
iv.
Division
/
v.
Modolus
%
vi.
Exponention
^
// This program demonstrates the use of arithmetic operators.
|
Output
10 + 5 = 15
10 - 5 = 5
10 * 5 = 50
10 / 5 = 2
10 % 5 = 0
10 ^ 2 = 100
|
# include <stdio.h>
# include <conio.h>
void main()
{
int a=10; b=5;
clrscr();
printf(“\n%d + %d = %d”, a, b, a+b);
printf(“\n%d - %d = %d”, a, b, a-b);
printf(“\n%d * %d = %d”, a, b, a*b);
printf(“\n%d / %d = %d”, a, b, a/b);
printf(“\n%d ^ 2 = %d”, a, b, a^2);
getch();
}
Example
14 – Arithmetic Operators
i.
And &&
ii.
Or ||
iii.
Not !
These operators will be
discussed with decision constructs
vii.
Greater than >
viii.
Less than <
ix.
Greater than or equal to >=
x.
Less than or equal to <=
xi.
Equal to ==
xii.
Not equal to!=
These operators will be
discussed with decision constructs
Bitwise – These are & (and), | (or). We will not discuss
them
2.
Ternary
– This operator has three operands. It is called conditional operator. This
will be discussed later with decision constructs.
Comments
Post a Comment