Advertisement
Solingen

z8.3.cpp

Dec 22nd, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include "string.h"
  3. #include "array.h"
  4. using namespace std;
  5.  
  6. // Структура для хранения тройки
  7. struct Triple
  8. {
  9.     int a, b, c;
  10. };
  11.  
  12. bool isPythagorean(int a, int b, int c)
  13. {
  14.     return (a*a + b*b == c*c);
  15. }
  16.  
  17. int main()
  18. {
  19.     int limit = 100;
  20.     Array<Triple> triples; // будем хранить все тройки здесь
  21.  
  22.     for (int a = 1; a <= limit; a++)
  23.     {
  24.         for (int b = a; b <= limit; b++)
  25.         {
  26.             for (int c = b; c <= limit; c++)
  27.             {
  28.                 if (isPythagorean(a, b, c))
  29.                 {
  30.                     Triple t;
  31.                     t.a = a;
  32.                     t.b = b;
  33.                     t.c = c;
  34.                     triples.append(t);
  35.                 }
  36.             }
  37.         }
  38.     }
  39.  
  40.     // Теперь вывод
  41.     for (int i = 0; i < triples.size(); i++)
  42.     {
  43.         // Формируем строку вывода
  44.         String msg = to_string(i+1).c_str();
  45.         msg = msg + ") (";
  46.         msg = msg + to_string(triples[i].a).c_str();
  47.         msg = msg + ", ";
  48.         msg = msg + to_string(triples[i].b).c_str();
  49.         msg = msg + ", ";
  50.         msg = msg + to_string(triples[i].c).c_str();
  51.         msg = msg + ")";
  52.         cout << msg << endl;
  53.     }
  54.  
  55.     return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement