1 条题解

  • 0
    @ 2086-11-9 15:42:12

    【深基1.例9】圆的计算

    解题思路

    圆周长为 2πr,面积为 πr²,球体积为 4πr³/3,直接代入 r=5 与题给 π。

    正确性说明

    三项几何公式分别得到题目要求的三个值,按顺序输出即可。

    易错点

    球体积中的 4/3 使用 4.0/3,按题意使用 cout 默认格式。

    复杂度

    时间 O(1),空间 O(1)。

    参考代码(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        double r = 5, pi = 3.141593;
        cout << 2 * pi * r << "\n" << pi * r * r << "\n" << 4.0 / 3 * pi * r * r * r << "\n";
        return 0;
    }
    
    • 1