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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
struct coordinates {
float x;
float y;
};
float dist_ab(struct coordinates a, struct coordinates b){
float dist_ab=sqrtf(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
return dist_ab;
}
float dist_ac(struct coordinates a, struct coordinates c){
float dist_ac=sqrtf(pow(a.x - c.x, 2.0) + pow(a.y - c.y, 2.0));
return dist_ac;
}
float dist_bc(struct coordinates b, struct coordinates c){
float dist_bc=sqrtf(pow(b.x - c.x, 2.0) + pow(b.y - c.y, 2.0));
return dist_bc;
}
void perimeter_abc(float dist_ab, float dist_ac, float dist_bc){
float perimeter_abc=dist_ab+dist_ac+dist_bc;
}
int main()
{
struct coordinates a;
struct coordinates b;
struct coordinates c;
float dab, dac, dbc;
float sum_abc;
printf("Insert the coordinates of point a: \n");
scanf("%f %f", &a.x, &a.y);
printf("Insert the coordinates of point b: \n");
scanf("%f %f", &b.x, &b.y);
printf("Insert the coordinates of point c: \n");
scanf("%f %f", &c.x, &c.y);
dab=dist_ab(a,b);
dac=dist_ac(a,c);
dbc=dist_bc(c,b);
sum_abc=perimeter_abc(dist_ab,dist_ac,dist_bc);
printf("Distance between points a and b: %f\n", dab);
printf("Distance between points a and c: %f\n", dac);
printf("Distance between points b and c: %f\n", dbc);
printf("Perimeter of the triangle abc: %f\n", sum_abc);
return 0;
}
|