C语言求球的体积和表面积,体积等于表面积?

错误代码:
#include<stdio.h>
#include<math.h>
int main()
{
const double PI = 3.14159;
double r, volume, surface_area;
printf("Please input the radius of the ball: ");
scanf("%lf", &r);
volume = 4PIpow(r,3)/3;
surface_area = 4PIpow(r,2);
printf("volume=%lf, surface_area=%lf", volume, surface_area);
}

img

改正后的:
#include<stdio.h>
#include<math.h>
int main()
{
const double PI = 3.14159;
double r, volume, surface_area;
printf("Please input the radius of the ball: ");
scanf("%lf", &r);
volume = 4/3PIpow(r,3);
surface_area = 4PIpow(r,2);
printf("volume=%lf, surface_area=%lf", volume, surface_area);
}

img

我不理解啊啊!!为什么,求体积的公式/3要放到4后面才对?而且,就算这个体积公式不对,为什么输出会等于面积啊?

你是不是贴反了
如果整数除法.4/3=1,如果除法运算中有一边是浮点数,则会当做浮点数运算,所以/3的位置影响结果

volume = 4.0/3*PI*pow(r,3);

没什么问题,修改如下,供参考:

#include<stdio.h>
#include<math.h>
int main()
{
    const double PI = 3.14159;
    double r, volume, surface_area;
    printf("Please input the radius of the ball: ");
    scanf("%lf", &r);
    volume = 4.0 * PI * pow(r, 3) / 3;
    //volume = 4.0 / 3 * PI * pow(r, 3);
    surface_area = 4.0 * PI * pow(r, 2);
    printf("volume=%lf, surface_area=%lf", volume, surface_area);
    return 0;
}