Turbo C编译器问题,sqrt()函数无法使用变量参数 [英] Turbo C compiler issue, sqrt() function not working with variable arguments
本文介绍了Turbo C编译器问题,sqrt()函数无法使用变量参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索了与我的问题类似的问题类似问题.但是我的问题是使用Turbo C编译器v3.0时.我是否需要对math.h文件做一些额外的工作?请帮忙.
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;
}
输出如下:
输入#作为平方根.
64
a = 0.000000
a = 0.000000
a = 0.000000且平方根为0.000000
a = 0.000000 and square root is 0.000000
推荐答案
对于scanf()
,%f
用于float
.您需要将%lf
用于double
:
For scanf()
, %f
is for float
. You need to use %lf
for double
:
printf("Enter a # for square root.\n");
scanf("%lf",&a);
这与printf()
相反,在printf()
中,类型促销允许%f
用于float
和double
.
This is in contrast to printf()
where type-promotion allows %f
to be used for both float
and double
.
这篇关于Turbo C编译器问题,sqrt()函数无法使用变量参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文