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));
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.
bit∙hub [bit-huhb] n. A source and destination for information.