C艹环境测试程序_两点距离计算

#include <stdio.h>
#include <stdlib.h>
#include <math.h> 
double distance(double x1,double y1,double x2,double y2);

int main() {
    int x1,x2,y1,y2;
    double D;
//  double distance;
    printf("\nEnter 2 coordinates(x1,y1,x2,y3)\n");
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    
    printf("\nThe first coordinate is (%d,%d)",x1,y1);
    printf("\nThe second coordinate is (%d,%d)",x2,y2);
    
 D=distance( x1, y1, x2, y2);
    
//  distance=sqrt(pow(x2-x1,2)+pow(y2-y1,2));//计算两点间的距离 
    printf("\nThe distance is %f",D)    ;
}
//写两点距离计算函数

 double distance(double x1,double y1,double x2,double y2)
 {
 
 double result=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
    return result;
 }

image.png

思路说明

(0,0)(3,4)两个点之间的距离为5
每次测试都是写hello world,不如写一个计算距离的测试程序。写着玩的,代码很乱,没什么参考价值。

posted @ 2019-11-19 23:57  寻松点点  阅读(...)  评论(... 编辑 收藏