TCS
Company
Programming
Technical
Parul takes as input two numbers: a and b. a and b can take integer values
between 0 and 255. She stores a, b and c as 1-byte data type. She writes the
following code statement to process a and b and put the result in c.
c = a + 2*b
To her surprise her program gives the right output with some input values of a and b,
while gives an erroneous answer for others. For which of the following inputs will it
give a wrong answer?
Read Solution (Total 2)
-
- a+2b=255
Or
a=255-2b
Max value possible of b to give positive value of a is b=127
So if b=127, a=1
b=126, a=3
....
b=1, a=253
So all value of a from 1 to 253 and b's from 127 to 1 respectively will give right answer.. else these.. answer may get erroneous. - 5 years agoHelpfull: Yes(4) No(0)
- Opyion a is right ans
- 5 years agoHelpfull: Yes(0) No(7)
TCS Other Question