Home > Programming > Functions using the "C" programming language > example30.c

 

Previous

Next


/*
    In this example we demonstrate the recursive function Ackermann.
*/

#include <conio.h>
#include <stdio.h>

/*
    Function prototype
*/
int Ackermann( int, int );

void main()
{
    int i,j;
    for ( i=0; i<5; i++ )
        for ( j=0; j<5; j++ )
            printf("Ackermann( %d, %d ) = %d.\n", i, j, Ackermann( i, j ));
    getch();
}

int Ackermann(int m, int n)
{
    if ( m == 0 )
        return n + 1;
    else
    {
        if( n == 0 )
            return Ackermann( m - 1, 0 );
        else
            return Ackermann( m - 1, Ackermann( m, n - 1 ));
    }
}


© 2004 Jim Valavanis

Previous

Next

1