Question: C++ Write a C++ program that implements the following three algorithms and times for various values of n. The program should display a table of

C++

Write a C++ program that implements the following three algorithms and times for various values of n. The program should display a table of the run times of each algorithm for various values of n.

I do not understand multidimensional arrays well. here is what i have.

#include // needed to perform C++ I/O

#include

using namespace std;

void ExA(int[], int);

void ExB(int[], int);

void ExC(int[], int);

const int MAXROWS = 8;

const int MAXCOL = 3;

int main()

{

//clock_t start, stop;

int sumArr[MAXROWS][MAXCOL] = { 100, 1000, 1100, 1500, 1800, 1900, 10000, 11000 };

cout << "Sum" << endl;

for (int i = 0; i < 8; i++)

{

for (int j = 0; j < 3; j++)

{

cout << "Input size n " << sumArr[i][j] << endl;

}

}

//start = clock();

//stop = clock();

/*cout << "The sum of the elelments in A is " << resA << endl;

cout << "Running time for Ex1 is " << static_cast(stop - start) / (CLOCKS_PER_SEC) << endl;

cout << endl;

cout << "The sum of the elelments in B is " << resB << endl;

cout << "Running time for Ex2 is " << static_cast(stop - start) / (CLOCKS_PER_SEC) << endl;

cout << endl;

cout << "The sum of the elelments in C is " << resC << endl;

cout << "Running time for Ex3 is " << static_cast(stop - start) / (CLOCKS_PER_SEC) << endl;

cout << endl;*/

system("pause");

return 0;

}

void ExA(int sumArr[], int n)

{

int sum = 0;

for (int i = 1; i <= n; i++)

sum = sum + 1;

}

void ExB(int sumArr[], int n)

{

int sum = 0;

for (int i = 1; i <= n; i++)

for (int j = 1; j <= i; j++)

sum = sum + i;

}

void ExC(int sumArr[], int n)

{

int sum = n * (n + 1) / 2;

}

//Algorithm A //Algorithm B //Algorithm C

sum = 0; sum = 0; sum = n * (n + 1) / 2

for(i = 1 to n) for(i = 1 to n)

sum = sum + 1 {

for(j = 1 to i)

sum = sum + i

}

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!