There is something I don't understand about casting. This works if I put a double in the place of (float)n.
Code:#include <math.h>
...
int n = 10;
....
printf("%f\n", sqrt((float)n));
Printable View
There is something I don't understand about casting. This works if I put a double in the place of (float)n.
Code:#include <math.h>
...
int n = 10;
....
printf("%f\n", sqrt((float)n));
What's your question? double and float are both floating point types, the difference is that double has more precision.
sqrt() takes a double type as the parameter. If you give it a int or a float, it will be implicitly converted to a double, so the cast is actually unnecessary.