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
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