dovrebbe essere giusto,scusate ma non riuscivo a ricontrollarlo.
questo calcola la distanza tra due punti(ax;ay)(bx;by).
ricorda che in un piano cartesiano serve il valore assoluto.
codice:
#include <stdio.h>
struct coord{
int x;
int y;
};
struct segmento{
struct coord a;
struct coord b;
}seg;
int lungx,lungy;
int lungxba(z,r,h);
int lungyba(l,m,n);
int main()
{
printf("inserisci le coord xa:\n");
scanf("%d",&seg.a.x);
printf("inserisci le coord ya:\n");
scanf("%d",&seg.a.y);
printf("inserisci le coord xb:\n");
scanf("%d",&seg.b.x);
printf("inserisci le coord yb:\n");
scanf("%d",&seg.b.y);
lungxba(lungx,seg.b.x,seg.a.x);
printf("%d",lungx);
lungyba(lungy,seg.b.y,seg.a.y);
printf("%d",lungy);
return 0;
}
int lungxba(z,r,h)
{
if(r>h)
{z=r-h;}
else
{z=(r-h)*-1;}
return 0;
}
int lungyba(l,m,n)
{
if(m>n)
{l=m-n;}
else
{l=(m-n)*-1;}
return 0;
}
ciao,
mercuzio