计算打印矩阵的函数步总数公式

#include<stdio.h>

int count=0;

#define MAX_SIZE 2

void printf_(int a[][MAX_SIZE], int rows, int cols);

int main(void)
{
		int a[MAX_SIZE][MAX_SIZE]={{2,3},{4,5}};
		
		printf_(a, MAX_SIZE,MAX_SIZE);
		printf("%d\n",count);
		return 0;
}
void printf_(int a[][MAX_SIZE],int rows, int cols)
{                                       /**********************/
	                                    /*se    频率   步数   */
	int i,j;                            /* 0    0      0      */
	for(i=0; i<rows; i++){count+=2;     /* 1    n+1    n+1    */
		for(j=0; j<cols; j++){          /* 1    n(n+1) n²+n   */
          /*printf("%d", a[i][k]);*/    /* 1    n*n    n²     */
				count+=2;               /*公式:2n²+2n+1       */ 
			}                           /**********************/
	}
	count++;
}


posted on 2017-12-30 11:17  MACHINE_001  阅读(109)  评论(0编辑  收藏  举报

导航