this program is use of random numbers, of matrix multiplication
/*For each element of the matrix, to release memory application*/
void cleanAll(void){
/*For each element of the matrix, print*/
void printMatrix(int **M, int row, int col){
/*The seed for random number, and then to do division, remove the remainder*/
void assignMatrix(int **M, int row, int col){
/*M[i][j] The range is 1-MAX_VALUE*/
M[i][j] = (1 + rand()%MAX_VALUE);
int main(int argc, char *argv[]){
/*Determine the number and value of input parameters, number is 4, the value is greater than 0*/
/*If the number of columns in the first row of the matrix and the number of the second matrix is not the same, so can not be calculated matrix*/
if(colA != rowB){
cout << "A(" << rowA << "," << colA << ") X B(" << rowB << "," << colB << ")\
not possible as cols of A and rows of B not same\n" << endl;
}
/*next,For the 2 matrix and the calculation results matrix space, and calculate the value of a matrix*/
start = clock();
for(i=0; i<rowA; i++){
for(j=0; j<colB; j++){
int sum =0;
for(k=0; k<rowB; k++){
sum += MatrixA[i][k] * MatrixB[k][j];
}
MatrixC[i][j] = sum;
}
}
end = clock();
long double runtime_s = (end-start)/(double)CLOCKS_PER_SEC;
/*Finally, using the calculation before and after the time, calculate the time difference, in order to calculate the matrix multiplication time*/