Advertisement
nikitaxe132

Untitled

Oct 10th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main() {
  4.     using namespace std;
  5.     bool iscorrect = true;
  6.     cout << "This program finds the triangle with the largest radius of the circumscribed circle\n";
  7.     int n;
  8.     do {
  9.         cout << "Enter the number of triangles n (n > 2 and n < 10)\n";
  10.         cin >> n;
  11.         if ((n > 1) && (n < 10)) {
  12.             iscorrect = false;  }
  13.         else {
  14.             cout << "This is a mistake. Please enter again!\n";
  15.             iscorrect = true;
  16.         }
  17.       }
  18.     while (iscorrect);
  19.     double a;
  20.     double b;
  21.     double c;
  22.     int nomb = 0;
  23.     double p;
  24.     double radius[10];
  25.     double max = 0;
  26.     for(int i = 0; i < n; i++) {
  27.         cout << "Enter the sides of triangle nomber  " << i+1 << "\n";
  28.         do {
  29.             do {
  30.                 cout << " First side = \n";
  31.                 cin >> a;
  32.                 if (a > 0) {
  33.                     iscorrect = false;  }
  34.                 else {
  35.                     cout << "This is a mistake. Please enter again!\n";
  36.                     iscorrect = true;
  37.                 }
  38.         }
  39.             while (iscorrect);
  40.             do {
  41.                 cout << " Second side = \n";
  42.                 cin >> b;
  43.                 if (b > 0) {
  44.                     iscorrect = false;  }
  45.                 else {
  46.                     cout << "This is a mistake. Please enter again!\n";
  47.                     iscorrect = true;
  48.                 }
  49.             }
  50.             while (iscorrect);
  51.             do {
  52.                 cout << " Third side = \n";
  53.                 cin >> c;
  54.                 if (c > 0) {
  55.                     iscorrect = false;  }
  56.                 else {
  57.                     cout << "This is a mistake. Please enter again!\n";
  58.                     iscorrect = true;
  59.                 }
  60.             }
  61.             while (iscorrect);
  62.         if ((a + b > c) && (a + c > b) && (b + c > a)) {
  63.             iscorrect = false;   }
  64.         else {
  65.             i = i -1;
  66.             cout << "This is a mistake. The sides of the triangle must satisfy the condition (a + b > c and a + c > b and b + c > a).\nPlease enter sides again!\n";
  67.         }
  68.                 p = (a + b + c) / 2;
  69.                 radius[i] = (a * b * c) / (4 * sqrt(p * (p - a) * (p - b) * (p - c)));
  70.                 if (max < radius[i]) {
  71.                     max = radius[i];
  72.                     nomb = i;
  73.                 }
  74.         }
  75.         while (iscorrect);
  76.     }
  77.     cout << " Triangle number " << nomb + 1 << " has the largest radius of the circumscribed circle = " << max << "\n";
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement