Ackermann Function
#10
Quote:Consolation prize: FreeBasic can't do any better! http://www.rosettacode.org/wiki/Ackerman...#FreeBASIC


Thanks!

"C" can it: Only "int" -> Ackermann Funktion

. . . but by myself the same problem. Code & screenshot.

Code: (Select All)
//Ackermann Funktion rekursiv - 15. Juli 2022
//Absturz schon bei 4, 1 = 65533 (?)

#include <stdio.h>
#include <stdlib.h>

long int ackermann(int m, int n);

int main(void)
{
  int m, n;
  printf("\nDemonstriert die Ackermann Funktion.\n");
    printf("\nGeben Sie zwei Zahlen ein a <> b: ");
  scanf("%d %d", &m,&n);
    
    for (int i = 0; i <= m; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            //i und j sonst wird nur das Endergebnis ausgegeben
            printf("\nAckerman(%d, %d) ergibt: %ld", i, j, ackermann(i, j));
        }
    }               
  return(0);
}

long int ackermann(int m, int n)
{
  if (!m) return n + 1;
  if (!n) return ackermann(m - 1, 1);
    return ackermann(m - 1, ackermann(m, n - 1));
}

[Image: In-C-auch-2022-07-16.jpg]
Reply


Messages In This Thread
Ackermann Function - by Kernelpanic - 07-15-2022, 04:50 PM
RE: Ackermann Function - by bplus - 07-15-2022, 05:59 PM
RE: Ackermann Function - by Kernelpanic - 07-15-2022, 09:18 PM
RE: Ackermann Function - by Kernelpanic - 07-15-2022, 10:29 PM
RE: Ackermann Function - by James D Jarvis - 07-15-2022, 10:40 PM
RE: Ackermann Function - by Kernelpanic - 07-15-2022, 11:19 PM
RE: Ackermann Function - by James D Jarvis - 07-15-2022, 11:57 PM
RE: Ackermann Function - by bplus - 07-15-2022, 10:48 PM
RE: Ackermann Function - by Kernelpanic - 07-15-2022, 11:15 PM
RE: Ackermann Function - by bplus - 07-15-2022, 11:26 PM
RE: Ackermann Function - by Kernelpanic - 07-15-2022, 11:45 PM
RE: Ackermann Function - by Kernelpanic - 07-16-2022, 12:16 AM
RE: Ackermann Function - by James D Jarvis - 07-16-2022, 12:39 AM
RE: Ackermann Function - by bplus - 07-16-2022, 01:02 AM
RE: Ackermann Function - by Kernelpanic - 07-16-2022, 08:39 PM
RE: Ackermann Function - by James D Jarvis - 07-16-2022, 03:09 PM
RE: Ackermann Function - by bplus - 07-16-2022, 04:38 PM
RE: Ackermann Function - by Kernelpanic - 07-16-2022, 08:29 PM
RE: Ackermann Function - by Jack - 07-16-2022, 10:16 PM
RE: Ackermann Function - by Kernelpanic - 07-16-2022, 10:52 PM
RE: Ackermann Function - by Jack - 07-16-2022, 11:47 PM
RE: Ackermann Function - by Kernelpanic - 07-19-2022, 02:44 PM
RE: Ackermann Function - by Jack - 07-19-2022, 05:29 PM
RE: Ackermann Function - by Kernelpanic - 07-19-2022, 08:43 PM
RE: Ackermann Function - by Jack - 07-19-2022, 10:05 PM
RE: Ackermann Function - by Kernelpanic - 07-19-2022, 10:53 PM
RE: Ackermann Function - by Jack - 07-19-2022, 11:23 PM
RE: Ackermann Function - by Jack - 07-19-2022, 11:40 PM
RE: Ackermann Function - by Kernelpanic - 07-20-2022, 12:44 AM
RE: Ackermann Function - by Jack - 07-20-2022, 12:52 AM
RE: Ackermann Function - by Kernelpanic - 07-20-2022, 11:40 AM
RE: Ackermann Function - by Kernelpanic - 07-20-2022, 08:44 PM



Users browsing this thread: 15 Guest(s)