#include <iostream> using namespace std; int main() {
double r=6371.0,pi=3.14; double s=0; s=4*pi*r*r; cout<<"表面积是:"<<s<<endl; cout<<"半径是:"<<r<<endl; cout<<"pi是:"<<pi<<endl; return 0; } //本人认为梁力上机实验书中代码有错误,球体表面积公式4*pi*r*r,体积4/3*pi*r*r*r
4*pi*r*r
,体积4/3*pi*r*r*r
#include <iostream> using namespace std; //用函数解决 double qiuBiaomianji() {
double r=6371.0,pi=3.14; double s=0; s=4*pi*r*r; cout<<"表面积是:"<<s<<endl; cout<<"半径是:"<<r<<endl; cout<<"pi是:"<<pi<<endl; } int main() {
qiuBiaomianji(); return 0; }
#include <iostream> using namespace std; //用函数解决 double qiuBiaomianji(double *r) {
double pi=3.14; double s=0; s=4*pi**r**r; cout<<"表面积是:"<<s<<endl; cout<<"半径是:"<<*r<<endl; cout<<"pi是:"<<pi<<endl; } int main() {
double r=0; cout<<"请输入半径r:"; cin>>r; qiuBiaomianji(&r); return 0; }