C Lv environmental test points _ distance calculating program

#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

Description ideas

(0,0) the distance between the (3,4) points to two 5
each test are written hello world, is better to write a test program for calculating a distance. The play was written, the code is a mess, no reference value.

Guess you like

Origin www.cnblogs.com/tamkery/p/11894436.html
lv