试图计算2点之间的距离

时间:2014-01-23 02:51:57

标签: c

/*----------------------------------------------------------------------------*/
/* Program Chapter 2 Modify                        */
/*                                                 */
/* This program calculates the                     */
/* distance between two points                     */

#include <stdio.h>
#include <math.h>

int main(void)
{
/* Declaration and initialization of variables.*/
double x1=1, y1=5, x2=4, y2=7, side_1, side_2, distance;

/* Compute the sides of a right triangle.      */
side_1 = x2 - x1;
side_2 = y2 - y1;
distance = sqrt(side_1*side_1 + side_2*side_2);

/* Print results.                              */
printf("The distance between the two points is ""%5.2f \n", distance);

/* Exit program.                               */
return 0;
}
/*----------------------------------------------------------------------------*/

我试图通过Visual Studio 2010在C中输出“两点之间的距离为3.61”并且它无法正常工作。这是我第一次写C程序。任何帮助深表感谢。

1 个答案:

答案 0 :(得分:1)

此行中有错误。它应该是

printf("The distance between the two points is %5.2f \n", distance);

请注意,那里有两个双引号。