Skip to content

Commit 4c440b3

Browse files
committed
new file: zad14
new file: zad14.c
1 parent 5f5150d commit 4c440b3

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

zad14

16.5 KB
Binary file not shown.

zad14.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <stdio.h>
2+
#include <math.h>
3+
struct POINT
4+
{
5+
int x;
6+
int y;
7+
};
8+
9+
float area( struct POINT, struct POINT, struct POINT );
10+
float perimeter( struct POINT, struct POINT, struct POINT );
11+
12+
int main()
13+
{
14+
struct POINT punkt1, punkt2, punkt3;
15+
16+
printf("Podaj Współrzędne punktu 1 (X Y): ");
17+
scanf("%d%d", &punkt1.x, &punkt1.y);
18+
printf("Podaj Współrzędne punktu 2 (X Y): ");
19+
scanf("%d%d", &punkt2.x, &punkt2.y);
20+
printf("Podaj Współrzędne punktu 3 (X Y): ");
21+
scanf("%d%d", &punkt3.x, &punkt3.y);
22+
23+
printf(" Pole trójkąta otrzymanego z zadanych współrzędnych to : %f\n", area( punkt1, punkt2, punkt3 ));
24+
printf(" Obwód trójkąta otrzymanego z zadanych współrzędnych to : %f\n", perimeter(punkt1, punkt2, punkt3 ));
25+
26+
return 0;
27+
28+
}
29+
30+
float area( struct POINT punktA, struct POINT punktB, struct POINT punktC )
31+
{
32+
/* tworzę statyczną tablicę 2d którą traktuję jak macierz i przypisuje jej wartości */
33+
34+
float tab[2][2];
35+
tab[0][0] = (punktB.x - punktA.x);
36+
tab[0][1] = (punktB.y - punktA.y);
37+
tab[1][0] = (punktC.x - punktA.x);
38+
tab[1][1] = (punktC.y - punktA.y);
39+
40+
/* liczę wyznacznik macierzy 2x2 i wstawiam go w wzór na pole */
41+
42+
float det = tab[0][0] * tab[1][1] - tab[0][1] * tab[1][0];
43+
44+
if(det < 0)
45+
{
46+
det = -det;
47+
}
48+
float pole = det/2;
49+
50+
return pole;
51+
}
52+
53+
float perimeter( struct POINT punktA, struct POINT punktB, struct POINT punktC)
54+
{
55+
/* wybieram dwa punkty i ilczę długość boku. */
56+
57+
float bok1 = sqrtf(powf(punktB.x - punktA.x,2) + powf(punktB.y - punktA.y, 2));
58+
float bok2 = sqrtf(powf(punktC.x - punktA.x,2) + powf(punktC.y - punktA.y, 2));
59+
float bok3 = sqrtf(powf(punktC.x - punktB.x,2) + powf(punktC.y - punktB.y, 2));
60+
/* następnie dla pozostałego punktu liczę długość boków i sumuję */
61+
62+
float obwod = bok1 + bok2 + bok3;
63+
64+
return obwod;
65+
}
66+
67+
68+
69+
70+
71+
72+
73+
74+

0 commit comments

Comments
 (0)