注意Π的值。
#include <iostream> #include <cstdio> #include <math.h> using namespace std; int main(){ int x0, y0, z0, x1, y1, z1, x; double radius, volumn; double PI = acos(-1); while(cin >> x0 >> y0 >> z0 >> x1 >> y1 >> z1){ x = pow((x0-x1), 2) + pow((y0-y1), 2) + pow((z0-z1), 2); radius = sqrt(x); volumn = PI * 4 / 3 * radius * radius * radius; printf("%.03f %.03f\n", radius, volumn); } }