I searched the question similar to my problem Similar problem. But my problem is when using Turbo C compiler v3.0. Should I have to do some additional work for math.h file? please help.
int main (void){
double result, a;
clrscr();
printf("Enter a # for square root.\n");
scanf("%f",&a);
printf("a = %f\n",a);
result = sqrt(a);
printf("a = %f and square root is %f\n",a, result);
getch();
return 0;
}
The Output is like this:
Enter a # for square root.
64
a = 0.000000
a = 0.000000 and square root is 0.000000
For scanf()
, %f
is for float
. You need to use %lf
for double
:
printf("Enter a # for square root.\n");
scanf("%lf",&a);
This is in contrast to printf()
where type-promotion allows %f
to be used for both float
and double
.