Fundamentals of Computer Programming - Old Questions

2. Find the value of “a” in each of the following statements:

int i=3 , j=4 ,k=8

float a=4.5 ,b=6.5,c=3.5

(a) a = b- i/k +c/k

(b) a = (b-k)/j + (j + c)/k

(c) a = c-(( i + j)/(k + i))*b

(d) a = c – i + j / k+ i * b

(e) a = c + j % 2 +b

(f) a = (b + 1) % (c + 1).

6 marks | Asked in 2065

a) a = b-i/k+c/k = 6.5-3/8+3.5/8 = 6.5-0+0.4375 = 6.9375

b) a = (b-k)/j+(j+c)/k = (6.5-8)/4+(4+3.5)/8 = 0.5625

c) a = c-((i+j)/(k+i))*b = 3.5-((3+4)/(8+3))*6.5 = 3.5-0*6.5 = 3.5

d)  a = c-i+j/k+i*b = 3.5-3+4/8+3 *6.5 = 3.5-3+0+19.5 = 0.5 + 19.5 = 20

e) a = c+j%2+b = 3.5+4%2+6.5 = 3.5+0+6.5 = 10

f) a = (b+1)%(c+1) = (6.5+1)%(3.5+1) = 7.5%4.5 = Not valid