What is the output when the following segment of ‘C’ code is executed? void…
2017
What is the output when the following segment of ‘C’ code is executed?
void main()
{
float a = 123.456;
printf("%.2f, %7.3f, %12e", a, a, a);
}
- A.
123.450, 123.4560, 1.234560e+02
- B.
123.46, 123.456, 1.234560e+02
- C.
123.456000, 123.456, 0.1234560e+03
- D.
123.45, 123.4560, 1.234560e+02
Attempted by 776 students.
Show answer & explanation
Correct answer: B
%.2frounds 123.456 to 2 decimal places, giving123.46.%7.3fprints with a minimum total width of 7 characters and 3 decimal places, matching the length of123.456perfectly.%12eprints in scientific notation with 6 default decimal places, padded with spaces to fit 12 characters:1.234560e+02.
Thus, the correct option is B.