Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- typedef struct
- {
- double x, y;
- }point_t;
- point_t readPoint(void);
- void printPoint(point_t d);
- double lengthSide(point_t a, point_t b);
- double trianglePerimeter(double a, double b, double c);
- double triangleVolume(double o, double a, double b, double c);
- int testPoint(point_t a, point_t b);
- int main()
- {
- point_t Point[3];
- double L[3], o, v;
- puts("Kolokwium 2 - IN - program testowy\n");
- printf("Podaj nastepujace punkty:\nA: ");
- Point[0] = readPoint();
- printf("B: ");
- Point[1] = readPoint();
- printf("C: ");
- Point[2] = readPoint();
- printf("\nPodano nastepujace punkty:\nA: ");
- printPoint(Point[0]);
- printf("B: ");
- printPoint(Point[1]);
- printf("C: ");
- printPoint(Point[2]);
- if(testPoint(Point[0], Point[1])&&testPoint(Point[1], Point[2])&&testPoint(Point[2], Point[0]))
- {
- L[0] = lengthSide(Point[0], Point[1]);
- L[1] = lengthSide(Point[1], Point[2]);
- L[2] = lengthSide(Point[2], Point[0]);
- o = trianglePerimeter(L[0], L[1], L[2]);
- v = triangleVolume(o, L[0], L[1], L[2]);
- if(v == 0) printf("Punkty leza na prostej - nie ma trojkata!\n");
- else
- {
- printf("\nObwod trojkata: %.2lf\n", o);
- printf("Pole trojkota: %.2lf\n\n",v);
- }
- }else
- {
- puts("\nPodano dwa takie same punkty!");
- }
- return 0;
- }
- point_t readPoint(void)
- {
- point_t d;
- printf("\tpodaj x: ");
- scanf("%lf", &d.x);
- fflush(stdin);
- printf("\tpodaj y: ");
- scanf("%lf", &d.y);
- fflush(stdin);
- return d;
- }
- int testPoint(point_t a, point_t b)
- {
- return (a.x == b.x && a.y == b.y) ? 0 : 1;
- }
- void printPoint(point_t d)
- {
- printf("x=%.2lf, y=%.2lf\n", d.x, d.y);
- }
- double lengthSide(point_t a, point_t b)
- {
- double l, e, f;
- e = b.y - a.y;
- e = pow(e,2);
- f = b.x - a.x;
- f = pow(f,2);
- l = sqrt(e+f);
- return l;
- }
- double trianglePerimeter(double a, double b, double c)
- {
- return a + b + c;
- }
- double triangleVolume(double p, double a, double b, double c)
- {
- double s;
- p /= 2;
- a = p-a;
- b = p-b;
- c = p-c;
- s = p*a*b*c;
- s = sqrt(s);
- return s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement