#include <stdio.h>
#include <math.h>
struct TemenaTrougla {
int xa,ya;
int xb,yb;
int xc,yc;
};
typedef struct TemenaTrougla TT;
double PovrsinaTrougla (TT teme) {
double a,b,c,s;
a=sqrt (pow((t.xa-t.xb),2)+pow((t.ya-t.yb),2));
b=sqrt (pow((t.xb-t.xc),2)+pow((t.yb-t.yc),2));
c=sqrt (pow((t.xa-t.xc),2)+pow((t.ya-t.yc),2));
s=(a+b+c)/2;
return sqrt (s*(s-a)*(s-b)*(s-c));
}
Uspevam samo da resim ovaj problem bez struktura ali je preopsiran:
#include <stdio.h>
#include <math.h>
main () {
double xA, yA, xB, yB, xC, yC, a, b, c, s, P;
/* Temena trougla: */
printf ("Koordinate temena trougla\n");
printf ("- prvo teme? "); scanf ("%lf%lf", &xA, &yA);
printf ("- drugo teme? "); scanf ("%lf%lf", &xB, &yB);
printf ("- trece teme? "); scanf ("%lf%lf", &xC, &yC);
/* Stranice trougla: */
a = sqrt (pow (xB-xC, 2) + pow (yB-yC, 2));
b = sqrt (pow (xC-xA, 2) + pow (yC-yA, 2));
c = sqrt (pow (xA-xB, 2) + pow (yA-yB, 2));
/* Površina trougla: */
s = (a + b + c) / 2;
P = sqrt (s * (s-a) * (s-b) * (s-c));
printf ("Povrsina trougla: %f\n", P);
}
I ovako dobijam resenje za povrsinu trougla u ravni.
Takodje, za povrsinu trougla u matrici imam problem u samom startu, nemam ideju kako bi napisao funkciju. Primer je sledeci:
U matrici dimenzija m x 6 cuvaju se koordinate temena m trouglova:
T0: XA,YA,XB,YB,XC,YC
T1: XA,YA,XB,YB,XC,YC
...
T(m-1):XA,YA,XB,YB,XC,YC
Koordinate temena trouglova su celi brojevi. Napisati program u jeziku C koji ucitava elemente prethodne matrice, a zatim izracunava ukupnu povrsinu svih trouglova. Rezultat ispisati na standardnom izlazu. Deo programskog koda koji izracunava povrsinu trougla izdvojiti u posebnu funkciju.
Unapred zahvalan na strpljenu
Andrej