In C with math.h included, what does this program print?\n\n#include<stdio.h>\n#include<math.h>\nint main()\n{\n printf("%f\n", sqrt(36.0));\n return 0;\n}\n\nAssume typical IEEE-754 and default printf formatting for %f.

Difficulty: Easy

Correct Answer: 6.000000

Explanation:


Introduction / Context:
This tests knowledge of sqrt from math.h and default floating-point formatting in printf. In C, %f prints a double value with six digits after the decimal by default.



Given Data / Assumptions:

  • sqrt(36.0) returns the principal square root as a double.
  • printf with "%f" prints six fractional digits unless precision is specified otherwise.
  • Headers are included correctly to provide prototypes.


Concept / Approach:
Compute sqrt(36.0) then format the result using "%f". No integer formatting or rounding tricks are involved; it is a direct call and a direct print.



Step-by-Step Solution:
Evaluate sqrt(36.0) → 6.0 (double).printf("%f", 6.0) → "6.000000".



Verification / Alternative check:
Changing the format to "%.1f" would print "6.0". Using "%g" would typically print "6".



Why Other Options Are Wrong:
"6.0" or "6": do not match the exact formatting of %f with default precision.Error: math.h is included; no prototype error occurs.



Common Pitfalls:
Confusing %f (fixed six decimals) with %g or custom precisions.



Final Answer:
6.000000

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion