• 2001


    计算2点之间的距离

     1 #include <stdio.h>
     2 #include <math.h>
     3 int mydistance(int a,int b,int c,int d);
     4 int main()
     5 {
     6     char buff[8];
     7     int buffer[4];
     8     while(gets(buff))
     9     {
    10         buffer[0] = buff[0] - '0';
    11         buffer[1] = buff[2] - '0';
    12         buffer[2] = buff[4] - '0';
    13         buffer[3] = buff[6] - '0';
    14         printf("%d
    ",mydistance(buffer[0],buffer[1],buffer[2],buffer[3]));
    15     }
    16     return 0;
    17 }
    18 
    19 int mydistance(int a,int b,int c,int d)
    20 {
    21     int e;
    22     e = sqrt((c - a)*(c - a) + (d - b)*(d - b));
    23     return e;
    24 }

    参考c++

     1 #include <cmath>
     2 #include <cstdio>
     3 
     4 int main(void)
     5 {
     6     double x[2], y[2];
     7 
     8     while (scanf("%lf%lf%lf%lf", x, y, x+1, y+1) != EOF)
     9         printf("%.2f
    ", sqrt((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0])));
    10 
    11     return 0;
    12 }
    ========================if i have some wrong, please give me a message, thx.========================
  • 相关阅读:
    MongoDB小结25
    MongoDB小结24
    MongoDB小结23
    MongoDB小结22
    MongoDB小结21
    MongoDB小结20
    MongoDB小结19
    MongoDB小结18
    hdu 4606 Occupy Cities
    hdu 4610 Cards
  • 原文地址:https://www.cnblogs.com/ailx10/p/5325472.html
Copyright © 2020-2023  润新知