求10个点到原点的距离和。输入10个点的坐标,计算并输出这些点到原点的距离和。定义函数dist(x, y),计算平面上任意一点(x, y)到原点(0, 0)的距离,函数返回值类型是double。
输入格式:
输入在一行中给出10对实数,每对实数对应一个点的横坐标和纵坐标。
输出格式:
在一行中按照“distance = S”的格式输出部分和的值S,精确到小数点后六位,请注意等号的左右各有一个空格。题目保证计算结果不超过双精度范围。
输入样例:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9
结尾无空行
输出样例:
distance = 63.639610
结尾无空行
#include <stdio.h>
#include <math.h>
double dist(double x,double y);
int main(int argc, char *argv[])
{
double x1,x2,x3,x4,x5,x6,x7,x8,x9,a,y1,y2,y3,y4,y5,y6,y7,y8,y9,z,s;
scanf("%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4,&x5,&y5,&x6,&y6,&x7,&y7,&x8,&y8,&x9,&y9,&a,&z);
s=dist(x1,y1)+dist(x2,y2)+dist(x3,y3)+dist(x4,y4)+dist(x5,y5)+dist(x6,y6)+dist(x7,y7)+dist(x8,y8)+dist(x9,y9)+dist(a,z);
printf("distance = %.6f\n",s);
return 0;
}
double dist(double x,double y)
{
double result;
result = sqrt((x-0)*(x-0)+(y-0)*(y-0));
return result;
}