Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Variables and Arithmetic operations: * / % +-++ --+= -= *= /= Example4 he follow

ID: 3875639 • Letter: V

Question

Variables and Arithmetic operations: * / % +-++ --+= -= *= /= Example4 he following sketch solve the following equation and print the result on the serial monitor k = (x2 + xy-11)/100 x=8,y=2 01) int x=8 ,y-2, temp ; 02) double k-0.0 03) void setup) t 04) // put your setup code here, to run once: 05) Serial.begin (9600) ; 06) k=(x#x+xty-11)/100; // line 6 07) serial, print( "k="); 08) Serial.printin (k): 09) 10) k-(x*x+xty-11)/100.0; /I line 10 11) Serial.print(" 12) Serial.println (k); 13) 14) temp-k;1 line 14 15) serial.print ("temp="); 16) Serial.println (temp) 17)) 18) 19) void loop) 20) // put your main code here, to run repeatedly: 21) 22) ) COMS (Arduino/Genuino Uno Send |k=0.00 k0.69 temp=0 Explain why the result in Line 6 is different than the result in Line 10. And why the variable "temp" (Line 14) is equal to zero even k is not?

Explanation / Answer

In line 6, x and y are integers, similarly 11 and 100 are also integers.. Hence any operation between integers, result in a integer number..
Hence (x^2 + xy - 11)/100 result in integer result.. As k is double, hence this integer result, which is 0, is translated to double, means 0.0.

In line 10, (x^2 + xy - 11) results in an integer result but the denominator is 100.0. 100.0 is not a integer, but a double datatype. as double datatype has more precision than integer, hence any operation between double and integer will result in double datatype. Hence (x^2 + xy - 11)/100.0 result in a double datatype result, which is 0.69.

In Line 14, temp is an integer and k is a double with value 0.69. when we convert a double type value to an integer, the decimal part is lost and only integral part is kept. Hence temp = 0 is stored, even when k is not zero(k=0.67).