Question

8. Ackermanns Function Ackermanns Function is a recursive mathematical algorithm that can be used to test how well a system

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Source Code:

#include <iostream> using namespace std; /*main function*/ int main() { /*function prototype*/ int ackermann(int,int); /*vari/*function defintion*/ int ackermann(int mint n) { /*if mis 0*/ if(m==0) return n+1; /*if n is a then call function recursive

Output:

C:\Users\Kumar Reddi\Desktop\trail.exe Enter the value of m: 3 Enter the value of n: 2 The result is: 29 Process exited after

Code in text format (See above images of code for indentation):

#include <iostream>
using namespace std;
/*main function*/
int main()
{  
   /*function prototype*/
   int ackermann(int,int);
   /*variables*/
   int result,m,n;
   /*read value of m from the user*/
   cout<<"Enter the value of m: ";
   cin>>m;
   /*read value of n from the user*/
   cout<<"Enter the value of n: ";
   cin>>n;
   /*function call*/
   result=ackermann(m,n);
   /*print result*/
   cout<<"The result is: "<<result;
   return 0;
}
/*function defintion*/
int ackermann(int m,int n)
{
   /*if m is 0*/
   if(m==0)
       return n+1;
   /*if n is 0 then call function recursively*/
   if(n==0)
       return ackermann(m-1,1);
   /*otherwise call function recursively*/
   else
       return ackermann(m-1,ackermann(m,n-1));
}

Add a comment
Know the answer?
Add Answer to:
8. Ackermann's Function Ackermann's Function is a recursive mathematical algorithm that can be used to test...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Code in python please! 8. Ackermann's Function Ackermann's Function is a recursive mathematical algorithm that can...

    Code in python please! 8. Ackermann's Function Ackermann's Function is a recursive mathematical algorithm that can be used to test how well a system optimizes its performance of recursion. Design a function ackermann (m, n), which solves Ackermann's function. Use the following logic in your function: If m 0 then return n + 1 If n = 0 then return ackermann(m – 1, 1) Otherwise, return ackermann(m – 1, ackermann(m, n - 1)) Once you've designed your function, test it...

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  • I am looking for toe menu "3" Ackermann table lookup function. IN JAVA I already made...

    I am looking for toe menu "3" Ackermann table lookup function. IN JAVA I already made my own menu, value, trace functions I just need table lookup function Ackermann's function Please create the following menu for the Ackermann project. This program allows you to call the Ackermann function. Please choose a version of Ackermann's Function. 1) Ackermann value. 2) Ackermann trace 3) Ackermann table lookup. 4) Quit playing with the Ackermann Function. Please choose one of the 4 choices Ackermann's...

  • C++ PROGRAM ONLY! For this lab you need to write a program that will read in...

    C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....

  • 3. Recursive Program (6 points) Consider the following recursive function for n 1: Algorithm 1 int...

    3. Recursive Program (6 points) Consider the following recursive function for n 1: Algorithm 1 int recurseFunc(int n) If n 0, return 1. If n 1, return 1 while i< n do while j <n do print("hi") j 1 end while i i 1 end while int a recurse Func(n/9); int b recurse Func (n/9) int c recurse Func (n/9) return a b c (1) Set up a runtime recurrence for the runtime T n) of this algorithm. (2) Solve...

  • IN MATLAB RECURSIVE FUNCTION 1. Sum of Factorials. The Recursive Function: A series that sums up...

    IN MATLAB RECURSIVE FUNCTION 1. Sum of Factorials. The Recursive Function: A series that sums up the factorial of the natural numbers from 1 to N can be expressed as The recursive algorithm: N-1 N-2 N-3 Write independent matlab code to solve the above problem with the following methods: 1. 2. 3. A monolithic program (with no functions) A standard (non-recursive) user defined function (an a program to call it) A recursive function (an a program to call it) Test...

  • 2. Consider the function george (int n) computed by the following recursive C++ code. int george ...

    2. Consider the function george (int n) computed by the following recursive C++ code. int george (int n) assert (n >= 0) if (n < 2) return 1; else return 2*george ((n+1)/2)+2*george (n/2)+2 george((n-1)/2)+2*george (n/2-1); (c) Design a memoization algorithm to compute george(n) for any given n. You do not have to write C++ code. This algorithm should be much faster than the dynamic programming algorithm. What is its time complexity? 2. Consider the function george (int n) computed by...

  • The following algorithm (Rosen pg. 363) is a recursive version of linear search, which has access...

    The following algorithm (Rosen pg. 363) is a recursive version of linear search, which has access to a global list of distinct integers a_1, a_2,..., a_n. procedure search(i, j, x : i,j, x integers, 1 < i < j < n) if a_i = x then return i else if i = j then 4. return 0 else return search(i + 1, j, x) Prove that this algorithm correctly solves the searching problem when called with parameters i = 1...

  • A growth-rate function is a mathematical function used to indicate an algorithm's time efficiency in terms...

    A growth-rate function is a mathematical function used to indicate an algorithm's time efficiency in terms of the size of the problem. a. True b. False If a problem of size n requires time that is directly proportional to n, the problem is ______. a. O(1) b. O(n)   c. O(n2)   d. O(log2 n)       The recursive binary search algorithm is a logarithmic algorithm. a. True b. False Which of the following growth-rate functions indicates a problem whose time requirement is...

  • I am stuck on trying to get this recursive function's logic to make it work. //Write...

    I am stuck on trying to get this recursive function's logic to make it work. //Write a recursive function that returns true if the sequence of 0 < n integers in A is sorted in non-increasing order and false otherwise. iostream and cmath libraries only bool is_sorted(const int *A, unsigned int n){ if (n == 0) return false; if (A > A+1) return true; else return false; }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT