Question: HOW TO USE MALLOC FOR MATRICES(code as is creates overfow) /////////////////////////////////////CODE//////////////////////////////////////////////////////////////////////////////////////////////// #include stdafx.h #include #include #include time.h using namespace std; #define n 1000 int main()

HOW TO USE MALLOC FOR MATRICES(code as is creates overfow)

/////////////////////////////////////CODE////////////////////////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include

#include

#include "time.h"

using namespace std;

#define n 1000

int main()

{

int *A[n*n];

int B[n*n];

int C[n*n];

int it;

int input;

int avgtime = 0;

clock_t time1, time2;

string close;

fill_n(A, n*n, rand());

fill_n(B, n*n, rand());

fill_n(C, n*n, 0);

//Start screen to enter user inputs

cout << endl << " Input NUmber of Iterations ";

cin >> input;

cout << endl << endl;

cout << " The code will go through " << input << " loops" << endl << endl;

// ikj test

cout << " \t IKJ Test" << endl;

for (it = 0; it < input; it++) {

time1 = clock();

for (int i = 0; i < n; i++) {

for (int k = 0; k < n; k++) {

for (int j = 0; j < n; j++) {

//C[i + j*n] += A[i + k*n] * B[k + j*n];

}

}

}

time2 = clock();

//avgtime += time2 - time1;

}

while (1) {

cout << " press d to exit" << endl;

cin >> close;

if (close == "d") {

break;

}

}

return 0;

}

////////////////////////////////////////END//////////////////////////////////////////////////////////////////////////////////

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!