Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <math.h>
- #include <string>
- using namespace std;
- int input(int& m) {
- bool IsNotCorrect;
- cout << "Введите m" << endl;
- do {
- IsNotCorrect = false;
- try {
- string value;
- cin >> value;
- m = stoi(value);
- }
- catch (...) {
- cout << "Введите натуральное число" << endl;
- IsNotCorrect = true;
- }
- if (m <= 0 && !IsNotCorrect) {
- cout << "Введите натуральное положительное число" << endl;
- IsNotCorrect = true;
- }
- } while (IsNotCorrect);
- return m;
- }
- bool getBool(int m, int** sos, int *count) {
- int x;
- int y;
- int z;
- int x3;
- int y3;
- int z3;
- int j;
- int i;
- int msqr;
- int order;
- bool boof;
- i = 0;
- order = (*count);
- msqr = round(sqrt(m / 3));
- boof = true;
- for (int i = 0; i < order; i++)
- {
- sos[i] = new int[3];
- }
- for (x = 1; x <= msqr; x++) {
- x3 = x * x * x;
- if (x3 < m) {
- for (y = 1; y <= msqr; y++) {
- y3 = y * y * y;
- if (x3 + y3 < m) {
- for (z = 1; z <= msqr; z++) {
- z3 = z * z * z;
- j = x3 + y3 + z3;
- if (j == m) {
- sos[i][0] = x;
- sos[i][1] = y;
- sos[i][2] = z;
- i++;
- (*count)++;
- boof = false;
- }
- }
- }
- }
- }
- }
- return boof;
- }
- void output(bool boof, int** sos, int count) {
- if (!boof) {
- cout << "Числа, удовлетворяющие условию:" << endl;
- for (int i = 0; i < count; i++) {
- for (int j = 0; j < 3; j++)
- {
- cout << sos[i][j] << "\t";
- }
- cout << endl;
- }
- }
- else {
- cout << "Не удалось подобрать числа X, Y, Z для данного числа M" << endl;
- }
- }
- int main()
- {
- int m;
- bool boof;
- int count;
- int** sos = new int* [3];
- setlocale(LC_ALL, "Russian");
- m = input(m);
- boof = getBool(m, sos, &count);
- output(boof, sos, count);
- }
Advertisement
Add Comment
Please, Sign In to add comment