about summary refs log tree commit diff
path: root/usth/ICT2.1/labwork/1/Ex3.c
blob: f20bb54919dd1d3938eaf0b2feac660f22fcc376 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 <math.h>
#include <stdio.h>

/*
 * 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;
}