Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int A(int m, int n) {
- if (m == 0) return n + 1;
- else if (n == 0) return A(m - 1, 1);
- else return A(m - 1, A(m, n - 1));
- }
- int just_A(int m, int n)
- {
- if (m == 0) return n + 1;
- else if (m == 1) return n + 2;
- else if (m == 2) return 2 * n + 3;
- else return pow(2, n + 3) - 3;
- }
- int main() {
- int m, n;
- cout << "Введите неотрицательные целые m и n: ";
- cin >> m >> n;
- if (m < 0 || n < 0) cout << "m и n должны быть неотрицательными";
- else cout << "Значение функции Аккермана (не рекурсивно): " << just_A(m, n)
- << "\nЗначение функции Аккермана (рекурсивно): " << A(m, n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement