Q:

Write a C Program to implement Ackermann function using recursion

0

Write a C Program to implement Ackermann function using recursion. Here’s simple Program to implement Ackermann’s function using recursion in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Recursion : :


  • Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.
  • The C programming language supports recursion, i.e., a function to call itself. But while using recursion, programmers need to be careful to define an exit condition from the function, otherwise it will go into an infinite loop.
  • Recursive functions are very useful to solve many mathematical problems, such as calculating the factorial of a number, generating Fibonacci series, etc.

Ackermann Function


The Ackermann function is the simplest example of a well-defined total function which is computable but not primitive recursive, providing a counterexample to the belief in the early 1900’s that every computable function was also primitive recursive . It grows faster than an exponential function, or even a multiple exponential function.

 
 

Below is the source code for C Program to implement Ackermann function using recursion which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :

/* C Program to implement Ackermann function using recursion */

#include<stdio.h>
int A(int m, int n);

main()
{
        int m,n;
        printf("Enter two numbers :: \n");
        scanf("%d%d",&m,&n);
        printf("\nOUTPUT :: %d\n",A(m,n));
}

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));
}

OUTPUT  : :


************* OUTPUT **************


************* FIRST RUN ***********


Enter two numbers ::
1
0

OUTPUT :: 2


************* SECOND RUN ***********

Enter two numbers ::
0
5

OUTPUT :: 6

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Recursion Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C Program to find frequency of vowels in S... >>
<< Write a C Program to calculate Binomial coefficien...