/* Program uvodi strukture - geometrijske figure */
#include <stdio.h>

/* Zbog funkcije sqrt. */
#include <math.h>

/* Tacke su predstavljene sa dve koordinate. Strukturom gradimo novi tip podataka. */
struct point
{
    int x;
    int y;
};

/* funkcija  Izracunava duzinu duzi zadatu sa dve tacke */
float rastojanje(struct point A, struct point 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(struct point A, struct point B, struct point 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)
{
    struct point A = {0,0};
    struct point B = {1,0};
    struct point C = {0,1};
    printf("povrsina trougla 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;
}

Last modified: Tuesday, 7 May 2019, 1:17 PM