Which header should be added so that the following program using log(36.0) compiles and links correctly? #include<stdio.h> int main() { printf("%f ", log(36.0)); return 0; }

Difficulty: Easy

Correct Answer: #include

Explanation:


Introduction:
The function log is part of the C math library. This question checks whether you can identify the correct header needed to declare and use log properly.


Given Data / Assumptions:

  • Function used: log(36.0)
  • Output via printf with %f
  • Standard C environment


Concept / Approach:
In C, mathematical functions such as log, exp, sin, and cos are declared in math.h. Including the proper header ensures correct declarations and types. Some toolchains also require linking with the math library (e.g., -lm) at link time.


Step-by-Step Solution:
1) Identify log as a natural logarithm function.2) Recall its declaration resides in math.h.3) Add the line #include to the program.4) If needed by the toolchain, link with the math library, e.g., gcc file.c -lm.


Verification / Alternative check:
Compile with and without the header to see that the version without math.h yields warnings or errors about implicit declaration or mismatched types.


Why Other Options Are Wrong:
conio.h: Non-standard header for console I/O on some DOS compilers; unrelated to log.stdlib.h: General utilities (malloc, exit, atoi, etc.), not log.dos.h: Platform-specific DOS functions; not math.


Common Pitfalls:
Forgetting to link the math library on Unix-like systems. Also, using %f in printf with log is fine because log returns double.


Final Answer:
#include

Discussion & Comments

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