知识点:
⚪的半径R:(x1-x0)^2+(y1-y0)^2+(z1-z0)^2=R^2
⚪的体积V:V = 4/3 * PI * R*R*R
C++输出格式化浮点数:fixed表示输出浮点数;setprecision(n),n为小数后有效位数
#include <iomanip> #include <iostream> using namespace std; #include<math.h> int main(){ double x0,y0,z0,x1,y1,z1; while(cin >> x0>> y0>>z0>>x1>>y1>>z1){ double PI = acos(double(-1)); double r = sqrt(pow(x1-x0,2)+pow(y1-y0,2)+pow(z1-z0,2)); double v = 4*PI * pow(r,3)/3; cout<<fixed<<setprecision(3)<<r<<" "<<fixed<<setprecision(3)<<v<<endl; } }