新手问个C语言问题
我想用display函数打印指定给数组的行和列,
比如display(2,4,a)打印数组a的前两行,前4列,
可是为什么执行后是
1.1, 2.2, 3.3, 4.4,
5.5, 6.6, 7.7, 8.8,
而不是
1.1, 2.2, 3.3, 4.4
6.6, 7.7, 8.8, 9.9
#include <stdio.h>#define COLS 5void display(int a,int b,double p[a][b] );int main(void){ double a[3][COLS] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10, 11.11, 12.12, 13.13, 14.14, 15.15 }; display(2,4,a); return 0;}void display(int rows,int cols,double p[rows][cols]){ int i,j; for(i=0;i<rows;i++) { for (j=0; j<cols; j++) printf("%g\t",p[i][j]); printf("\n"); } putchar('\n');}
#include <stdio.h>#define COLS 5void display(int rows,int cols,double (*p)[COLS]);int main(void){ double a[3][COLS] = { {1.1, 2.2, 3.3, 4.4, 5.5}, {6.6, 7.7, 8.8, 9.9, 10.10}, {11.11, 12.12, 13.13, 14.14, 15.15} }; display(2,4,a); return 0;}void display(int rows,int cols,double (*p)[COLS]){ int i,j; for(i=0;i<rows;i++) { for (j=0; j<cols; j++) printf("%g\t",p[i][j]); printf("\n"); } putchar('\n');}//1.1 2.2 3.3 4.4//6.6 7.7 8.8 9.9//Press any key to continue