ackfunction.cpp

来自「实现阿克曼函数并统计递归调用次数 Counting times of recu」· C++ 代码 · 共 59 行

CPP
59
字号
// ACKFunction.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


// ACKfunction.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;

unsigned int  count;



long int ACK(unsigned int  m,unsigned int n)
{	
	int p;
	if(m==0)
	{
		count++;
		return n+1;
	}
	else	if(n==0)
		{	
			count++;
		
			return ACK(m-1,1);
		}
			else
			{
			count++;
			p=ACK(m,n-1);
			return ACK(m-1,p) ;
			}			
	
	
}

void main()
{	
	unsigned int  m;
	unsigned int  n;
	unsigned int  x;
	count=0;
	
	cout<<"input m:";
	cin>>m;
	cout<<"input n:";
	cin>>n;
	x=ACK(m,n);
	cout<<"the result is:"<<x<<endl;
	cout<<"count="<<count<<endl;

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?