#include <stdio.h>
#include "func.h"
#include <math.h>
#include <stdlib.h>
int main() {
float x, y;
Ponto *a = cria(1.0,4.0);
Ponto *b = cria (1.0,3.0);
acessa(a, &x, &y);
printf("ponto a:(%f,%f)\n",x,y);
acessa(b, &x, &y);
printf("ponto b:(%f,%f)\n",x,y);
float c = dist(a,b);
printf("Distancia Euclidiana: %f\n", c);
libera(a);
libera(b);
return 0;
}
typedef struct ponto Ponto;
Ponto *cria(float x, float y);
void libera (Ponto* p);
void acessa (Ponto* p, float* x, float* y);
void atribui (Ponto* p, float x, float y);
float dist (Ponto* p1, Ponto* p2);
#include <stdio.h>
#include <stdlib.h>
#include "func.h"
#include <math.h>
struct ponto {
float x, y;
};
Ponto* cria(float x, float y) {
Ponto *p = (Ponto*) malloc(sizeof(Ponto));
p -> x = x;
p -> y = y;
return p;
}
void libera (Ponto* p) {
free(p);
}
void acessa (Ponto* p, float* x, float* y) {
*x = p -> x;
*y = p -> y;
}
void atribui (Ponto* p, float x, float y) {
p -> x = x;
p -> y = y;
}
float dist (Ponto* p1, Ponto* p2) {
float dx = p2 -> x - p1 -> x;
float dy = p2 -> y - p1 -> y;
return sqrt(dx*dx + dy*dy);
}