Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int readNumPositive()
- {
- int num;
- bool isIncorrect;
- do
- {
- isIncorrect = false;
- std::cin >> num;
- if (std::cin.fail())
- {
- std::cin.clear();
- while (std::cin.get() != '\n');
- isIncorrect = true;
- std::cerr << "Symbols have been entered or exceeding permissible limits.
- Enter the number : ";
- }
- if (!isIncorrect && std::cin.get() != '\n')
- {
- while (std::cin.get() != '\n');
- std::cerr << "Incorrect value. Enter the number: ";
- isIncorrect = true;
- }
- if (!isIncorrect && num < 0)
- {
- std::cerr << "Incorrect value (num must be > 0). Enter a valid value: ";
- isIncorrect = true;
- }
- } while (isIncorrect);
- return num;
- }
- int countRoot(int num)
- {
- float float_MAX;
- int MAX;
- float_MAX = (pow(num, 0.333333));
- float_MAX = round(float_MAX);
- MAX = static_cast<int>(float_MAX);
- return MAX;
- }
- void showCombinations(int& k, int MAX, int num)
- {
- int x;
- int y;
- int z;
- MAX++;
- for (x = 0; x < MAX; x++)
- {
- for (y = 0; y < MAX; y++)
- {
- for (z = 0; z < MAX; z++)
- {
- if (x * x * x + y * y * y + z * z * z == num)
- {
- std::cout << x << " " << y << " " << z << std::endl;
- k++;
- }
- }
- }
- }
- }
- void showResult(int& k)
- {
- if (k != 0)
- {
- std::cout << "Finite number of combinations: " << k;
- }
- else
- {
- std::cout << "There are no combinations.";
- }
- }
- void whatDoesTheProgramDo()
- {
- std::cout << "The program indicates all triples of numbers X, Y, Z, that satisfy
- the condition: X^3 + Y^3 + Z^3 = Num." << std::endl;
- }
- int main()
- {
- int num;
- int x;
- int y;
- int z;
- int k;
- int MAX;
- whatDoesTheProgramDo();
- k = 0;
- std::cout << "Enter the number: ";
- num = readNumPositive();
- MAX = countRoot(num);
- showCombinations(k, MAX, num);
- showResult(k);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement