Created
November 5, 2020 15:04
-
-
Save timurbakibayev/cf99b596e53d13af889ea4e087ab8505 to your computer and use it in GitHub Desktop.
Matrix Multiplication in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main(int argc, const char * argv[]) { | |
int n = 800; | |
int a[n][n], b[n][n], mult[n][n], i, j, k; | |
for(i = 0; i < n; ++i) | |
for(j = 0; j < n; ++j) | |
a[i][j] = 1; | |
for(i = 0; i < n; ++i) | |
for(j = 0; j < n; ++j) | |
b[i][j] = 1; | |
for(i = 0; i < n; ++i) | |
for(j = 0; j < n; ++j) | |
mult[i][j]=0; | |
std::cout << std::endl << "Starting after matrix initialization..." << std::endl; | |
clock_t tStart = clock(); | |
for(i = 0; i < n; ++i) | |
for(j = 0; j < n; ++j) | |
for(k = 0; k < n; ++k) | |
mult[i][j] += a[i][k] * b[k][j]; | |
std::cout << std::endl << "I did it in "<< (double)(clock() - tStart)/CLOCKS_PER_SEC << "sec" << std::endl; | |
for(i = 0; i < 5; ++i) | |
for(j = 0; j < 5; ++j) | |
{ | |
std::cout << " " << mult[i][j]; | |
if(j == 4) | |
std::cout << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment