Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

Students also viewed these Databases questions

Question

=+Where does the focus of labor relations lie? Is it collective

Answered: 1 week ago

Question

=+With whom does the firm have to negotiate?

Answered: 1 week ago