#include "stdio.h"#include <stdlib.h>int main(int argv,char *argc[]){ int n,**a,*b,i,j; printf("Input n(int 2<n<8)...\nn="); if(scanf("%d",&n)!=1 || n<3 || n>7){ printf("Input error, exit...\n"); return 0; } b=(int *)malloc(sizeof(int)*n*n); if(!b || (a=(int **)malloc(sizeof(int*)*n))==NULL){ printf("Application memory failure...\n"); return 0; } for(j=i=0;i<n;a[i++]=b+j,j+=n); for(i=0;i<n;i++){ for(j=0;j<n;printf("%3d",a[i][j++]=i*j)); printf("\n"); } free(b); free(a); return 0; }
运行样例:
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/8c1001e93901213f736fdd4f58e736d12e2e95c1?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)