Zadatak br.3 sa vežbi
/* Koriscenje typedef radi lakseg rada */
#include <stdio.h>
#include <math.h>
/* Ovim se omogucava da se nadalje u programu umesto int moze
koristiti ceo_broj */
typedef int ceo_broj ;
/* Ovim se omogucuje da se nadalje u programu umesto struct point
moze koristiti POINT */
typedef struct point TACKA;
struct point
{
/* Umesto int mozemo koristiti ceo_broj */
ceo_broj x;
ceo_broj y;
};
/* funkcija Izracunava duzinu duzi zadatu sa dve tacke
a za tip koristimo TACKA */
float rastojanje(TACKA A, TACKA B)
{
int dx, dy;
dx = abs(A.x - B.x);
dy = abs(A.y - B.y);
return sqrt(dx*dx + dy*dy);
}
/*funkcija Izracunava povrsinu trougla Heronovim obrascem.
Argumenti funkcije su tri tacke koje predstavljaju temena trougla */
float HERON(TACKA A, TACKA B, TACKA C)
{
/* Duzine stranica */
float a,b,c,s;
a = rastojanje(B, C);
b = rastojanje(A, C);
c = rastojanje(A, B);
/* Poluobim */
s = (a+b+c)/2;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
int main(void)
{
TACKA A = {0,0};
TACKA B = {1,0};
TACKA C = {0,1};
printf("povrsina trougla (0,0)-(1,0)-(0,1)je %.2f",HERON(A,B,C));
printf("\n unesi koordinate temena trougla:");
printf("A: x="); scanf("%d",&A.x);
printf("A: y="); scanf("%d",&A.y);
printf("\nB: x="); scanf("%d",&B.x);
printf("B: y="); scanf("%d",&B.y);
printf("\nC: x="); scanf("%d",&C.x);
printf("C: y="); scanf("%d",&C.y);
printf("\n povrsina trougla je %.2f",HERON(A,B,C));
return 0;
}