Advertisement
ProgNeo

Untitled

Nov 5th, 2021
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. setlocale(LC_ALL, "rus");
  6. int n;
  7. cout << "Дано натуральное число N. Указать все тройки x, y, z таких натуральных чисел, что N=x^2+y^2+z^2\n\n";
  8. cout << "Введите n: ";
  9. while (!(cin >> n) || (cin.peek() != '\n')) {
  10. cin.clear();
  11. while (cin.get() != '\n');
  12. cout << "Введите n: ";
  13. }
  14. for (int x = 0; x < n; x++)
  15. for (int y = 0; y < n; y++)
  16. for (int z = 0; z < n; z++)
  17. if (n == x * x + y * y + z * z)
  18. cout << "x = " << x << " y = " << y << " z = " << z << endl;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement