Advertisement
themlgyo

ТиТП1

Feb 28th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. ######################################
  2.  
  3. Задача на расчет расстояния м/у 2 точками в X, Y, Z
  4.  
  5. #include <cmath>
  6. #include <iostream>
  7. #include <iomanip>
  8. using std::cout;
  9. using std::cin;
  10. using std::endl;
  11. int main()
  12. {
  13.     cout << "Please enter A (x1,y1,z1) = " << endl;
  14.     double x1{};
  15.     cin >> x1;
  16.     double y1{};
  17.     cin >> y1;
  18.     double z1{};
  19.     cin >> z1;
  20.     cout << "Please enter B (x2,y2,z2) = " << endl;
  21.     double x2{};
  22.     cin >> x2;
  23.     double y2{};
  24.     cin >> y2;
  25.     double z2{};
  26.     cin >> z2;
  27.     double R;
  28.     R = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2) + pow((z2 - z1), 2));
  29.     cout << std::setprecision(10) << "The distance between A (x1,y1,z1) and B (x2,y2,z2) = " << R << endl;
  30.     return 0;
  31. }
  32.  
  33. #############################
  34.  
  35. Задача на на нахождение P и S произвольного треугольника
  36.  
  37. #include <cmath>
  38. #include <iostream>
  39. #include <iomanip>
  40. using std::cout;
  41. using std::cin;
  42. using std::endl;
  43. int main()
  44. {
  45.     cout << "Please enter A (x1,y1) = " << endl;
  46.     double x1{};
  47.     cin >> x1;
  48.     double y1{};
  49.     cin >> y1;
  50.     cout << "Please enter B (x2,y2) = " << endl;
  51.     double x2{};
  52.     cin >> x2;
  53.     double y2{};
  54.     cin >> y2;
  55.     cout << "Please enter C (x3,y3) = " << endl;
  56.     double x3{};
  57.     cin >> x3;
  58.     double y3{};
  59.     cin >> y3;
  60.     double N;
  61.     N = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
  62.     double M;
  63.     M = sqrt(pow((x3 - x2), 2) + pow((y3 - y2), 2));
  64.     double K;
  65.     K = sqrt(pow((x3 - x1), 2) + pow((y3 - y1), 2));
  66.     double P;
  67.     P = N + M + K;
  68.     double L;
  69.     L = P*0.5;
  70.     double S;
  71.     S = sqrt(L*(L - N)*(L - M)*(L - K));
  72.     cout << std::setprecision(10) << "AB = " << N << endl;
  73.     cout << std::setprecision(10) << "BC = " << M << endl;
  74.     cout << std::setprecision(10) << "AC = " << K << endl;
  75.     cout << std::setprecision(10) << "P = " << P << endl;
  76.     cout << std::setprecision(10) << "S = " << S << endl;
  77.     return 0;
  78. }
  79.  
  80. #########################################
  81.  
  82. Задача на нахождение суммы четырехзначного числа
  83.  
  84. #include <cmath>
  85. #include <iostream>
  86. using std::cout;
  87. using std::cin;
  88. using std::endl;
  89. int main()
  90. {
  91.     cout << "Please enter number = " << endl;
  92.     int N, x1, x2, x3, x4 {};
  93.     cin >> N;
  94.     x4 = N % 10;
  95.     x3 = N / 10 % 10;
  96.     x2 = N / 100 % 10;
  97.     x1 = N / 1000;
  98.     int S;
  99.     S = x1 + x2 + x3 + x4;
  100.     cout << "S = " << S << endl;
  101.     return 0;
  102. }
  103.  
  104. #################################
  105.  
  106. Задача на нахождение суммы трехзначного числа:
  107.  
  108. #include <cmath>
  109. #include <iostream>
  110. using std::cout;
  111. using std::cin;
  112. using std::endl;
  113. int main()
  114. {
  115.     cout << "Please enter number = " << endl;
  116.     int N, x1, x2, x3 {};
  117.     cin >> N;
  118.     x3 = N % 10;
  119.     x2 = N / 10 % 10;
  120.     x1 = N / 100;
  121.     int S;
  122.     S = x1 + x2 + x3;
  123.     cout << "S = " << S << endl;
  124.     return 0;
  125. }
  126.  
  127. ###################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement