计算圆面积C语言问题,代码如下:#include #include double distance(double x1,double y1,double x2,double y2){double dx = x2 - x1;double dy = y2 - y1;double dsquared = dx * dx + dy * dy;double result = sqrt(dsquared);return result;}double ar

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 17:29:05
计算圆面积C语言问题,代码如下:#include#includedoubledistance(doublex1,doubley1,doublex2,doubley2){doubledx=x2-x1;d

计算圆面积C语言问题,代码如下:#include #include double distance(double x1,double y1,double x2,double y2){double dx = x2 - x1;double dy = y2 - y1;double dsquared = dx * dx + dy * dy;double result = sqrt(dsquared);return result;}double ar
计算圆面积C语言问题,代码如下:
#include
#include
double distance(double x1,double y1,double x2,double y2)
{
double dx = x2 - x1;
double dy = y2 - y1;
double dsquared = dx * dx + dy * dy;
double result = sqrt(dsquared);
return result;
}
double area(double radius)
{
return 3.1416 * radius * radius;
}
int main(void)
{
double x1,y1,x2,y2; /* float?double?*/
printf("请输入坐标:\n");
scanf("%f,%f %f,%f",&x1,&y1,&x2,&y2);
double radius = distance(x1,y1,x2,y2);
double result = area(radius);
printf("distance is %f\n",distance(x1,y1,x2,y2));
printf("area = %f\n",result);
return 0;
}
在main函数中第一句,为什么double会报错成
area.c:23:2:警告:格式 ‘%f’ expects argument of type ‘float *’,but argument 2 has type ‘double *’ [-Wformat]
area.c:23:2:警告:格式 ‘%f’ expects argument of type ‘float *’,but argument 3 has type ‘double *’ [-Wformat]
area.c:23:2:警告:格式 ‘%f’ expects argument of type ‘float *’,but argument 4 has type ‘double *’ [-Wformat]
area.c:23:2:警告:格式 ‘%f’ expects argument of type ‘float *’,but argument 5 has type ‘double *’ [-Wformat]
为什么会这样,希望懂C语言的朋友指点指点

计算圆面积C语言问题,代码如下:#include #include double distance(double x1,double y1,double x2,double y2){double dx = x2 - x1;double dy = y2 - y1;double dsquared = dx * dx + dy * dy;double result = sqrt(dsquared);return result;}double ar
记住了,scanf()中double型对应的控制符必须是%lf,float型的控制符必须是%f,不然就必然出错.而在输出函数printf()中,在控制符%f下可以输出任何浮点数.这些规定在教科书中都有明确儒术.