Day#98 C' Coding Challenge

Day#98 C' Coding Challenge

What is the output of the below code?

#include <stdio.h> #include <math.h> int main() { printf("%d",sqrt(49.0)); printf("%f",sqrt(49.0)); return 0; }

------------------------------------------

The above code uses the sqrt() function from math.h library.

The return type of sqrt() defaults to double. Below is the declaration of sqrt() function.

double sqrt(double arg);

The printf() function is above code has format specifiers integer, float. While integer does not give a correct value, float gives the correct value. 

The output of printf("%d",sqrt(49.0)); is 0.
The output of printf("%f",sqrt(49.0)); is 7.0.

Post a Comment

0 Comments