B2606为啥WA?

题目总版

zhege122 @ 2024-11-03 17:31:53

#include <bits/stdc++.h>

using namespace std;

const double PI = 3.141593;

int main() {
    double r = 5;
    double C = 2 * r * PI;
    double S = PI * pow(r, 2);
    double V = (4 / 3) * PI * pow(r, 3);
    cout << C << endl;
    cout << S << endl;
    cout << V << endl;

    return 0;
}

by Martin0310 @ 2024-11-03 17:42:55

@zhege122 double V = (4 / 3) * PI * pow(r, 3);中把 4 换成 4.0 ,就可以AC。 因为C++算 4 \div 3时,由于除数为整数,会自动四舍五入。


by zhege122 @ 2024-11-03 17:45:35

@Martin0310 好的,太感谢了!!!已关


by SuperAlex4 @ 2024-11-03 18:02:12

@Martin0310 向零取整*


|