-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathL4_5.c
More file actions
33 lines (29 loc) · 644 Bytes
/
Copy pathL4_5.c
File metadata and controls
33 lines (29 loc) · 644 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct tponto
{
int x;
int y;
} tPonto;
int main()
{
tPonto *ponto;
int n, i = 0;
float x_variacao = 0, y_variacao = 0, distancia;
scanf("%d", &n);
ponto = malloc(n * sizeof(tPonto));
scanf("%d %d", &ponto[i].x, &ponto[i].y);
printf("-\n");
i = 1;
for( i; i < n; i++ )
{
scanf("%d %d", &ponto[i].x, &ponto[i].y);
x_variacao = ponto[i].x - ponto[i-1].x;
y_variacao = ponto[i].y - ponto[i-1].y;
distancia = sqrt(((x_variacao)*(x_variacao))+((y_variacao)*(y_variacao)));
printf("%.2f\n", distancia);
}
free(ponto);
return 0;
}