From 0887d8f96950a060a122e14ed2981182ff1eb37d Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sat, 28 Dec 2019 21:16:58 +0700 Subject: [usth/ICT2.1] Algorithm and Data Structures --- usth/ICT2.1/labwork/1/Ex3.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 usth/ICT2.1/labwork/1/Ex3.c (limited to 'usth/ICT2.1/labwork/1/Ex3.c') diff --git a/usth/ICT2.1/labwork/1/Ex3.c b/usth/ICT2.1/labwork/1/Ex3.c new file mode 100644 index 0000000..f20bb54 --- /dev/null +++ b/usth/ICT2.1/labwork/1/Ex3.c @@ -0,0 +1,33 @@ +/* + * Read coordinates of 2 2D-points from stdin and print their distance to stdout + * This is free and unencumbered software released into the public domain. + */ + +#include +#include + +/* + * The overhead caused by re-evaluating x in this case is much + * to change this into a function call. + */ +#define SQR(x) ((x) * (x)) + +/* Conventionally C names are in lowercase */ +struct point { + double x, y; +}; + +double distance(struct point u, struct point v) +{ + return sqrt(SQR(u.x - v.x) + SQR(u.y - v.y)); +} + +int main() +{ + struct point m, n; + + scanf("%lf %lf %lf %lf", &m.x, &m.y, &n.x, &n.y); + printf("%g\n", distance(m, n)); + + return 0; +} -- cgit 1.4.1