-1
printf("%d",pow(5,3))

it's printing 0, and works fine when number is different from 5 why?

Can anyone explain this ?

Cool
  • 27
  • 1
  • 5
  • 2
    `pow()` takes in `double` and returns `double` – Haris Oct 24 '15 at 10:33
  • 2
    `pow()` returns a double, use `%f` or `%lf`. Check out [The C Library Reference Guide](https://www-s.acm.illinois.edu/webmonkeys/book/c_guide/) – maddouri Oct 24 '15 at 10:35

3 Answers3

3

The return type of the power function is double. using the double conversion specifier to prints the output of power function.

the conversion specifier for double is not "%d". It should be "%f".

1

It should be:

printf("%f",pow(5,3));

Since return type of pow is double

Roman Pustylnikov
  • 1,937
  • 1
  • 10
  • 18
1

You have to use %lf or %f:

 printf("%lf",pow(5,3));

As pow function returns double.