By | 25.03.2017

# C Program to implement Ackermann function

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.

## 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```

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.

Thanks for reading the post….

4.3 12 votes
Article Rating
Category: C Programming Recursion Programs Tags:

## About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of

2 Comments
Inline Feedbacks
View all comments

there is just a small error ( error is a big word to use here)
the error is the missing void keyword before main();
i don’t know why it showed me the error but acc to me its not actually a big problem some platform may run it even void keyword isn’t used……

bakwaas definition hain