Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Oct 15th, 2006, 4:47 PM   #1
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
Ackerman's function - crash upon launch

This is a simple program that evaluates ackerman's function given 2 values. It opens and closes extremely quickly, no doubt a crash. Can anyone see the problem?

#include <iostream>
#include <cstdlib>
using namespace std; 

int A(int, int);

int A(int in_m, int in_n)
{
        int m = in_m;
        int n = in_n;
        
        if( m == 0 && n >= 0)
        {
            return (A(n + 1,0), 0);
        }
        else if(m>0 && n == 0)
        {
             return (A(m-1, 1));
        }
        else if( m>0 && n>0)
        {
             return( A(m-1, A(m, n-1)));
        }
}
             

int main()
{
    char ch;
    cout << A(0,0) << endl;
    cout << A(0,9) << endl;
    cout << A(1,8) << endl;
    cout << A(2,2) << endl;
    cout << A(2,0) << endl;
    cout << A(2,3) << endl;
    cout << A(3,2) << endl;
    cout << A(4,0) << endl;

    cin >> ch;
    return 0;

}

Thanks
codylee270 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining languages titaniumdecoy Other Programming Languages 12 Jul 13th, 2006 2:03 PM
Compiling Maverik 6.2 (from C) megamind5005 C 16 May 3rd, 2006 5:41 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
Jackpot game zorin Visual Basic 3 Jun 10th, 2005 1:19 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC