Q2 Given the constant and variable declarations #define E 2.78 #define MAX 100 d
ID: 3710145 • Letter: Q
Question
Q2 Given the constant and variable declarations #define E 2.78 #define MAX 100 double x, y; int a, b, i; indicate which of the following statements are valid and where valid, give the value stored into the target variable. Assume that a is 4, b is 3, and y is -2.0 (a) 1 a%b; (c ) a % b * b; (e) x-E*y (g) X-E y (i) x=a%(a / b); (k) x (double) a / b; (b) -(MAX -90)/a; (d) x=a/y; (f) a*E; (h)x b/a; (j) x-b%(b / a); (I) x = (double) (a/ b); Redo the above question with new values of 3 for a, 7 for b, and 3.0 for yExplanation / Answer
Answer 2:
a) Valid statement
i = 1
simple modulus operator
b) Valid statement
i = 2
c) Valid statement
i = 3
d) Valid statement
x = -2.00000
e) Valid statement
x = -5.560000
f) Valid statement
i = 11
g) Valid statement
x = -1.390000
h) Valid statement
x = 0.000000
i) Valid statement
x = 0.000000
j) Statement is valid, but no value will be assigned to the x because b/a will give 0 and then 3%0 will give something like....
k) Valid statement
x = 1.333333
because type casting is performed on a so a first will cast to double then division will be performed.
l) Valid statement
x = 1.000000
because type casting is performed on (a/b), first division will be performed then will be casted in double.
Note: As above we can easily find out the values for a =3, b= 7, and y = 3.0.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.