gpt4 book ai didi

c - cp 中的二维数组

转载 作者:行者123 更新时间:2023-11-30 18:15:39 24 4
gpt4 key购买 nike

#include<stdio.h>
int main(){
int i=0,j=0;
char a[5][2];
for(i=0;i<5;i++){
for(j=0;j<2;j++){
scanf("%c",&a[i][j]);
}
}
for(i=0;i<5;i++){
for(j=0;j<2;j++){
printf("\n %c \n",a[i][j]);
printf("\t");
}
printf("\n");
}
return 0;
}

i/p:一个顾标准差欧共体

我没有得到任何输出。

我正在尝试在二维数组上编写一个简单的程序。我无法获得输出,并且输入不占用 5*2 个字符,而是只占用 4*2 个字符。

最佳答案

粘贴我的代码,在%c之前留一个空格。

   #include<stdio.h>
int main(){
int i=0,j=0;
char a[5][2];
for(i=0;i<5;i++){
for(j=0;j<2;j++){
scanf(" %c",&a[i][j]);
}
}
for(i=0;i<5;i++){
for(j=0;j<2;j++){
printf("\n %c \n",a[i][j]);
printf("\t");
}
printf("\n");
}
return 0;
}

关于c - cp 中的二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15320302/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com