Created
August 3, 2019 19:55
-
-
Save heronyang/7c8e410f27615b2f8579bfcde13494ac to your computer and use it in GitHub Desktop.
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
/* point.c */ | |
#include "point.h" | |
#include <stdlib.h> | |
#include <math.h> | |
struct Point { | |
double x, y; | |
} | |
struct Point* makePoint(double x, double y) { | |
struct Point* p = malloc(sizeof(struct Point)); | |
p->x = x; | |
p->y = y; | |
return p; | |
} | |
double getDistance(struct Point* p1, struct Point *p2) { | |
double dx = p1->x - p2->x; | |
double dy = p1->y - p2->y; | |
return sqrt(dx*dx + dy*dy); | |
} |
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
/* point.h */ | |
struct Point; | |
struct Point* makePoint(double x, double y); | |
double getDistance(struct Point *p1, struct Point *p2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment