C 当我需要字母字符时,程序生成数字
我的代码:C 当我需要字母字符时,程序生成数字,c,loops,nested,C,Loops,Nested,我的代码: #include <stdio.h> int main() { char x, y; for(x='a';x<='c';++x) { for(y='a';y<='c';++y) { printf("%c %d\r\n",x,y); } } return(0); } 我想要: a a b a c b a b b。。。等 我得到: a 97 a 98 a 99 b 97 b 98。。。等 我缺少什么?这是我
#include <stdio.h>
int main()
{
char x, y;
for(x='a';x<='c';++x)
{
for(y='a';y<='c';++y)
{
printf("%c %d\r\n",x,y);
}
}
return(0);
}
我想要:
a
a b
a c
b a
b b。。。等
我得到:
a 97
a 98
a 99
b 97
b 98。。。等
我缺少什么?这是我的第一个程序和第一次编译。感谢您的回复。 我将一行更改为:
printf("%c %d\r\n",x,y);
致:
我有很多东西要学://你有一个%d在里面printf@PiRocks不会的。char值将经历默认参数升级为int。事实上,%d和%c都需要int类型的参数。@PiRocks-不,不会。在对printf的调用中,由于省略号。。。在printf原型的末尾。
printf("%c %c\r\n",x,y);