急!求C程序高手,帮忙做下面的题目。急!
来源:百度知道 编辑:UC知道 时间:2024/07/04 09:08:41
Double recursion function
Ackermann Function is defined as
ack(0,n) = n + 1
ack(m,0) = ack( m-1, 1)
ack(m,n) = ack( m – 1, ack( m, n – 1 ))
For example
ack( 1, 1 )
= ack ( 0, ack ( 1, 0 ) )
= ack ( 0 , ack( 0, 1 ) )
= ack ( 0, 2 )
= 3
Try to work out ack( 1 , 2 ) and ack ( 1, 3 ) by hand.
Write a program that will accept two parameters and display the value of the corresponding Ackermann function. For example:
$ ack 1 1
The Ackermann value of ack(1,1) is 3
Using your program, try to find out the values of ack(2,3), ack(3,2) and ack(4,2).
WARNING!!!! It may not be as easy as it looks
Ackermann Function is defined as
ack(0,n) = n + 1
ack(m,0) = ack( m-1, 1)
ack(m,n) = ack( m – 1, ack( m, n – 1 ))
For example
ack( 1, 1 )
= ack ( 0, ack ( 1, 0 ) )
= ack ( 0 , ack( 0, 1 ) )
= ack ( 0, 2 )
= 3
Try to work out ack( 1 , 2 ) and ack ( 1, 3 ) by hand.
Write a program that will accept two parameters and display the value of the corresponding Ackermann function. For example:
$ ack 1 1
The Ackermann value of ack(1,1) is 3
Using your program, try to find out the values of ack(2,3), ack(3,2) and ack(4,2).
WARNING!!!! It may not be as easy as it looks
#include <iostream.h>
int ack(int m, int n);
void main()
{
int m, n;
cout << "请输入Ackerman函数的参数m 和 n: ";
cin >> m >> n;
cout << ack(m, n) << endl;
}
int ack(int m, int n)
{
if (m==0)
return n+1;
else if (n==0)
return ack(m-1, 1);
else
return ack(m-1, ack(m, n-1));
}
学习一下。
看不懂!