function Call of C language 12-recursive method to find Ackerman function

Source: Internet
Author: User

Recursive Method!
/*
===========================================
Title: A recursive function program that writes the Ackermann function!

A (m,n) =

    • N+1 (m=0)
    • A (m-1,1) (m=0)
    • A (M-1,a (m,n-1)) (m!=0,n!=0)

===========================================
*/
#include <stdio.h>
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));
}
void Main ()
{
int m,n,p,flag=1;
while (flag)
{
printf ("m=");
scanf ("%d", &m);
printf ("n=");
scanf ("%d", &n);
P=a (M,n);
printf ("A (%d,%d) =%d\n\n", m,n,p);
}
}
/*
===========================================
Evaluation:

This topic is very simple, has clarified the specific form of recursive function, directly

Write a function, call it! However, if the hand is to be counted, this is a phase

When the complex call process, if you let m and n are calculated from 1 to 10 respectively,

It may take an hour! Take the computer a few minutes to get it done!

===========================================
*/

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

function Call of C language 12-recursive method to find Ackerman function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.