Tutorial 04 - Expressions and Operators
Tutorial 04 - Expressions and Operators
int i, j;
long l;
short s;
float f;
double d;
char c;
3. Given int a = 1, b = 10; What is the output produced by the following code segment?
Statement Output
printf("a = %d, b = %d\n", a++, b++);
printf("a = %d, b = %d\n", ++a, ++b);
printf("a = %d, b = %d\n", --a, b--);
printf("a = %d, b = %d\n", a--, b--);
4. Convert the following mathematical equations into C statements (treat each letter as
an individual variable):
a) p= 2(w+h)
b) a
s= (xy-mn)
b
c) m+n
u=
x-y
d) a(b+c)
t= +3xy
1-mn
Page 1 of 2
AACS1074 Programming Concepts and Design I Tutorial 4
(b) Negate the following condition (for invalid mark) using DeMorgan's Theorem:
mark < 0 || mark > 100
int i = 8, j = 5;
double x = 0.005, y = -0.01;
char c = 'c', d = 'd';
Determine the value of each of the following expressions. Use the value initially
assigned to the variables for each expressions.
Expression Value
a) (3 * i – 2 * j) % (2 * d – c)
b) 2 * ((i / 5) + (4 * (j – 3)) % (i + j – 2))
c) -(i + j)
d) ++i
e) i<=j
f) c>d
g) X >=0
h) j != 6
i) 5 * (i + j) > 'c'
j) 2 * x + y == 0
k) !(i <= j)
l) !(c == 99)
m) !(x > 0)
n) (j < 5) && (i > 0)
o) (i > 0) || (j < 5)
p) (x > y) && (i > 0) || (j < 5)
Page 2 of 2