Question: I want to make my code run. This is my code. How can I measure time elased for calculating Ackermann function? If I run my

I want to make my code run.

This is my code.

How can I measure time elased for calculating Ackermann function?

If I run my code below, it always shows me 0 seconds. I think that is wrong.

I want to make code run by reducing // in //code_to_time();

What should I add to make this code run including code_to_time(); ???

Please help me..

----------------------------------------------------------------------------------------------------------------------------------------

#include // cin, cout

#include // For calculation.

#include // string

#include

using namespace std; // std::cout - > cout

// function prototype

double A(int, int); // The Ackermann function A(m,n)

void main()

{

int num1, num2; // number

cout << "Enter an two integer values ";

cout << " I will display the value of the Ackermann function" << endl;

cin >> num1 >> num2; // User will type numbers

clock_t begin, end;

begin = clock();

//code_to_time(); <<-- **** How can I make this code run to calculate how many times elapsed??

end = clock();

double elapsed_secs = (double(end - begin) / CLOCKS_PER_SEC);

// Try ... catch phrase

try

{

//Display the result

cout << "A(" << num1 << ", " << num2 << ")" << " answer is ";

cout << A(num1, num2) << " and it took " << elapsed_secs << " seconds." << endl;

}

catch (string exceptionString) // For the exception string

{

cout << exceptionString;

}

system("pause");

}

// Define A function

double A(int m, int n)

{

if (m == 0)

{ // If m = 0 return n + 1;

return n + 1;

}

if (m < 0 || n < 0)

{ // If m < 0 OR n < 0 throw an error.

string exceptionString = "Error ";

throw exceptionString;

}

if (n == 0)

{ // If n = 0 then return A(m-1, 1)

return A(m - 1, 1);

}

if (m > 0 && n > 0) // If m > 0 and n > 0 return A(m-1, A(m, n-1))

return A(m - 1, A(m, n - 1));

}

------------------------------------------------------------------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!