Last active
December 13, 2015 23:49
-
-
Save lacom/4994334 to your computer and use it in GitHub Desktop.
Distance between 2 points in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <cmath> | |
using namespace std; | |
// Prototypes | |
double Distance(double x1, double y1, double x2, double y2); | |
int main() | |
{ | |
// local vars | |
double x1 = 4; | |
double y1 = 5; | |
double x2 = -4; | |
double y2 = -5; | |
double distance; | |
distance = Distance(x1, y1, x2, y2); | |
cout<<endl<<distance<<endl<<endl; | |
system("pause"); | |
return 0; | |
} | |
/*************************************************** | |
Function Name: Distance | |
Arguments: double x1, double y1, double x2, double y2 | |
Returns: distance | |
***************************************************/ | |
double Distance(double x1, double y1, double x2, double y2) | |
{ | |
double distance; | |
distance = pow((pow((x2-x1), 2) + pow((y2-y1), 2)), 0.5); | |
return distance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment