試過了,但沒有按預期作業:
#include <stdio.h>
int main()
{
int arr[2][2] = {10,11,12,13};
int i,j;
for(i = 0; i<2; i )
{
printf("ds%d",i 1);
printf("\n");
for(j = 0; j<2; j )
{
printf("%d\t", arr[i][j]);
}
}
return 0;
}
出現的結果:
ds1
10 11 ds2
12 13
所需的結果應該如下:
ds1 ds2
10 11
12 13
uj5u.com熱心網友回復:
您需要先單獨列印標題。
int main()
{
int arr[2][2] = {10,11,12,13};
int i,j;
/* This loop prints the headers */
for(i = 0; i<2; i )
{
printf("ds%d\t",i 1);
}
printf("\n"); /* new line to start printing data */
/* This loop prints the data */
for(i = 0; i<2; i )
{
for(j = 0; j<2; j )
{
printf("%d\t", arr[i][j]);
}
printf("\n"); /* new line after each row of data */
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/427730.html
