Bob103

норма

Sep 28th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. double otrezok(double x1, double y1, double x2, double y2)
  8. {
  9. double result;
  10. result = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
  11. return result;
  12. }
  13.  
  14. bool IsTriangle(double a, double b, double c)
  15. {
  16. double eps = 1e-3; // точность вычислений до одной тысячной
  17. return (b + c - a > eps) && (a + c - b > eps) && (a + b - c > eps);
  18. }
  19.  
  20. int main()
  21. {
  22. const int n = 4;
  23. double x[n], y[n], a, b, c;
  24. int count = 0;
  25. cout << "Input coords of points:" << endl;
  26. for (int i = 0; i < n; ++i)
  27. {
  28. cout << "Point " << i + 1 << endl;
  29. cout << "\tx" << i + 1 << ": ";
  30. cin >> x[i];
  31. cout << "\ty" << i + 1 << ": ";
  32. cin >> y[i];
  33. }
  34. for (int i = 0; i < n - 2; ++i)
  35. for (int j = i + 1; j < n - 1; ++j)
  36. for (int k = j + 1; k < n; ++k)
  37. {
  38. a = otrezok(x[i], y[i], x[j], y[j]);
  39. b = otrezok(x[j], y[j], x[k], y[k]);
  40. c = otrezok(x[i], y[i], x[k], y[k]);
  41. if (IsTriangle(a, b, c))
  42. ++count;
  43. }
  44. cout << "Number of triangles: " << count << endl;
  45. system("pause");
  46. }
Advertisement
Add Comment
Please, Sign In to add comment