动态分配的二维数组以矩阵形式输出
麻烦帮我看下为什么这样不能以矩阵形式输出啊
/*#include <stdio.h>C
#include <stdlib.h>
void main()
{
int n,i=0,j=0;
int **p;
printf("?????????:");
scanf("%d", &n);
p = (int**)calloc(n, sizeof(int*));
for (i = 0; i < n; i++)
{
p[i] = (int*)calloc(n + 1, sizeof(int));
for (j = 0; j < n; j++)
{
scanf("%d", &p[i][j]);
p[i][n] += p[i][j];
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n+1 ; j++)
{
printf("%d ", p[i][j]);
}
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n+1 ; j++)
{
printf("%d ", p[i][j]);
}
printf("\n"); //这里必须要个的换行符呢!
} // 还有每次输入数据的时候,后面加个getchar()函数,吃掉每次输入的回车符!
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
int n,i=0,j=0;
int **p;
printf("?????????:");
scanf("%d", &n);
p = (int**)calloc(n, sizeof(int*));
for (i = 0; i < n; i++)
{
p[i] = (int*)calloc(n + 1, sizeof(int));
for (j = 0; j < n; j++)
{
scanf("%d", &p[i][j]);
p[i][n] += p[i][j];
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
printf("%d ", p[i][j]);
}
printf("\n");
}
return 0;
}