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
#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
cout << endl;
cout << "The sum of the elelments in B is " << resB << endl;
cout << "Running time for Ex2 is " << static_cast
cout << endl;
cout << "The sum of the elelments in C is " << resC << endl;
cout << "Running time for Ex3 is " << static_cast
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started