Advertisement
DominikPasiut

Untitled

Dec 18th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct
  5. {
  6.     double x, y;
  7. }point_t;
  8.  
  9. point_t readPoint(void);
  10. void printPoint(point_t d);
  11. double lengthSide(point_t a, point_t b);
  12. double trianglePerimeter(double a, double b, double c);
  13. double triangleVolume(double o, double a, double b, double c);
  14. int testPoint(point_t a, point_t b);
  15.  
  16. int main()
  17. {
  18.     point_t Point[3];
  19.     double L[3], o, v;
  20.  
  21.     puts("Kolokwium 2 - IN - program testowy\n");
  22.     printf("Podaj nastepujace punkty:\nA: ");
  23.     Point[0] = readPoint();
  24.     printf("B: ");
  25.     Point[1] = readPoint();
  26.     printf("C: ");
  27.     Point[2] = readPoint();
  28.  
  29.     printf("\nPodano nastepujace punkty:\nA: ");
  30.     printPoint(Point[0]);
  31.     printf("B: ");
  32.     printPoint(Point[1]);
  33.     printf("C: ");
  34.     printPoint(Point[2]);
  35.  
  36.     if(testPoint(Point[0], Point[1])&&testPoint(Point[1], Point[2])&&testPoint(Point[2], Point[0]))
  37.     {
  38.         L[0] = lengthSide(Point[0], Point[1]);
  39.         L[1] = lengthSide(Point[1], Point[2]);
  40.         L[2] = lengthSide(Point[2], Point[0]);
  41.         o = trianglePerimeter(L[0], L[1], L[2]);
  42.         v = triangleVolume(o, L[0], L[1], L[2]);
  43.         if(v == 0) printf("Punkty leza na prostej - nie ma trojkata!\n");
  44.         else
  45.         {
  46.             printf("\nObwod trojkata: %.2lf\n", o);
  47.             printf("Pole trojkota: %.2lf\n\n",v);
  48.         }
  49.     }else
  50.     {
  51.         puts("\nPodano dwa takie same punkty!");
  52.     }
  53.     return 0;
  54. }
  55.  
  56. point_t readPoint(void)
  57. {
  58.     point_t d;
  59.     printf("\tpodaj x: ");
  60.     scanf("%lf", &d.x);
  61.     fflush(stdin);
  62.  
  63.     printf("\tpodaj y: ");
  64.     scanf("%lf", &d.y);
  65.     fflush(stdin);
  66.  
  67.     return d;
  68. }
  69.  
  70. int testPoint(point_t a, point_t b)
  71. {
  72.     return (a.x == b.x && a.y == b.y) ? 0 : 1;
  73. }
  74.  
  75. void printPoint(point_t d)
  76. {
  77.     printf("x=%.2lf, y=%.2lf\n", d.x, d.y);
  78. }
  79.  
  80. double lengthSide(point_t a, point_t b)
  81. {
  82.     double l, e, f;
  83.     e = b.y - a.y;
  84.     e = pow(e,2);
  85.     f = b.x - a.x;
  86.     f = pow(f,2);
  87.     l = sqrt(e+f);
  88.     return l;
  89. }
  90.  
  91. double trianglePerimeter(double a, double b, double c)
  92. {
  93.     return a + b + c;
  94. }
  95.  
  96. double triangleVolume(double p, double a, double b, double c)
  97. {
  98.     double s;
  99.     p /= 2;
  100.     a = p-a;
  101.     b = p-b;
  102.     c = p-c;
  103.     s = p*a*b*c;
  104.     s = sqrt(s);
  105.     return s;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement