计算矩阵乘法函数步总数的公式

#include<stdio.h>

int count=0;

#define MAX_SIZE 2

void mult(int a[][MAX_SIZE], int b[][MAX_SIZE],
		 int c[][MAX_SIZE], int rows, int cols);

int main(void)
{
		int a[MAX_SIZE][MAX_SIZE]={{9,8},{2,3}};
		int b[MAX_SIZE][MAX_SIZE]={{6,7},{8,9}};
		int c[MAX_SIZE][MAX_SIZE];
		
		mult(a,b,c, 2,MAX_SIZE);
		printf("%d
",count);
		return 0;
}
void mult(int a[][MAX_SIZE], int b[][MAX_SIZE],
		 int c[][MAX_SIZE], int rows, int cols)
{
	int i,j,k;
	for(k=0; k<rows; k++){        //se:1 频率:n+1 步数:n+1
			count+=2;
		for(i=0; i<rows; i++){   //se:1  频率:n(n+1) 步数:n²+n
			count+=3;
//			c[k][i]=0;           //se:1  频率:n²  步数:n²
			for(j=0; j<rows; j++){ //se:1 频率:n^3+n²  步数:n^3+n²
					count+=3;
//				c[i][j]=a[i][k]*b[k][j];
//	            printf("%d
", c[i][j]);
                                 //se:1  频率:2n^3  步数:2n^3
                                 //公式:1+2n+3n²+3n^3
			}
		}
	}
	count++;
}

原文地址:https://www.cnblogs.com/WALLACE-S-BOOK/p/9732311.html