Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "string.h"
- #include "array.h"
- using namespace std;
- // Структура для хранения тройки
- struct Triple
- {
- int a, b, c;
- };
- bool isPythagorean(int a, int b, int c)
- {
- return (a*a + b*b == c*c);
- }
- int main()
- {
- int limit = 100;
- Array<Triple> triples; // будем хранить все тройки здесь
- for (int a = 1; a <= limit; a++)
- {
- for (int b = a; b <= limit; b++)
- {
- for (int c = b; c <= limit; c++)
- {
- if (isPythagorean(a, b, c))
- {
- Triple t;
- t.a = a;
- t.b = b;
- t.c = c;
- triples.append(t);
- }
- }
- }
- }
- // Теперь вывод
- for (int i = 0; i < triples.size(); i++)
- {
- // Формируем строку вывода
- String msg = to_string(i+1).c_str();
- msg = msg + ") (";
- msg = msg + to_string(triples[i].a).c_str();
- msg = msg + ", ";
- msg = msg + to_string(triples[i].b).c_str();
- msg = msg + ", ";
- msg = msg + to_string(triples[i].c).c_str();
- msg = msg + ")";
- cout << msg << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement