fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Punkt {
  5. double x, y;
  6. };
  7.  
  8. double det(Punkt A, Punkt B, Punkt P) {
  9. return (B.x - A.x) * (P.y - A.y) - (B.y - A.y) * (P.x - A.x);
  10. }
  11.  
  12. Punkt czytaj_punkt(double x, double y) {
  13. Punkt p;
  14. p.x = x;
  15. p.y = y;
  16. return p;
  17. }
  18.  
  19. void punkty_po_stronie(Punkt A, Punkt B, Punkt P) {
  20. double d = det(A, B, P);
  21.  
  22. if (d > 0)
  23. cout << "Pkt. P lezy po lewej stronie prostej" << endl;
  24. else if (d < 0)
  25. cout << "Pkt. P lezy po prawej stronie prostej" << endl;
  26. else
  27. cout << "Pkt. P lezy na prostej" << endl;
  28. }
  29.  
  30. int main() {
  31. Punkt A, B, P;
  32.  
  33. A = czytaj_punkt(1,1);
  34. B = czytaj_punkt(3,3);
  35. P = czytaj_punkt(0,3);
  36.  
  37. punkty_po_stronie(A, B, P);
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Pkt. P lezy po lewej stronie prostej