zoukankan      html  css  js  c++  java
  • Distance Between Points

    I need some help. I have to create a function that will calculate the distance between points (x1,y1) and (x2, y2). All numbers are of type double. I keep getting incorrect output. I am usinge visual studio and C language. Here is my code.

    #include <stdio.h>
    #include <math.h> 
    
    
    double calculate_distance (double x1,double y1,double x2 ,double y2)
    
    {
    
    double distance;
    
    double distance_x = x1-x2;
    
    double distance_y = y1- y2; 
    
    distance = sqrt( (distance_x * distance_x) + (distance_y * distance_y));
    
    return distance;
    
    }
    
    int main ()
    {
    double x1;
    
    double x2;
    
    double y1;
    
    double y2; 
    
    
    printf ("Let me help you find the distance between two points (x1,y1) and (x2, y2)."); 
    
    printf ("
    
    Enter coordinate for x1:");
    scanf ("%f", &x1); 
    
    printf ("
    Enter coordinate for y1:");
    scanf ("%f", &y1); 
    
    
    printf ("
    Enter coordinate for x2:");
    scanf ("%f", &x2); 
    
    
    printf ("
    Enter coordinate for y2:");
    scanf ("%f", &y2); 
    
    
    printf ("The distance between (%f,%f) and (%f,%f) is %.2f
    
    ", x1,y1,x2,y2, calculate_distance(x1,y1,x2,y2)); 
    
    
    return 0;
    
    } 
  • 相关阅读:
    邮箱整理
    C++ Primer Plus 6 笔记(1)
    MySQL的远程链接
    MySQL的安装和使用
    nginx的反向代理和负载均衡
    linux--配置开发环境 --Nginx篇
    linux--配置开发环境 --Apache篇
    Linux -- 运维
    Linux
    使用宝塔面板部署tp5网站
  • 原文地址:https://www.cnblogs.com/kissfu/p/3363192.html
Copyright © 2011-2022 走看看