小编Ong*_*aya的帖子

计算球体体积时出错,但公式是正确的

我想计算球体的表面积和球体的体积,但球体的体积不正确。如果我输入 r=3 则 V=84.8229980469 而不是 V=113.0973358154,尽管球体的公式体积是正确的。请帮我。这是我的代码。

#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<math.h>
using namespace std;
float surface_area_of_sphere(float r)
{
    float L;
    L=4*3.14159265359*r*r;
    return L;
}

float volume_of_sphere(float r, float &V)
{
    V=4/3*3.14159265359*r*r*r;
}

int main()
{
    float radius,volume,area;
    cout<<"Please input radius of sphere r = ";
    cin>>radius;
    cout<<"==================================="<<endl;
    volume_of_sphere(radius,volume);
    cout<<"Volume of sphere = ";
    printf("%10.10f\n",volume);
    area=surface_area_of_sphere(radius);
    cout<<"Surface area of sphere = ";
    printf("%10.10f",area);
    getch();
}
Run Code Online (Sandbox Code Playgroud)

c++ function formula

2
推荐指数
1
解决办法
872
查看次数

标签 统计

c++ ×1

formula ×1

function ×1