这个程序哪里错了?
创始人
2025-07-15 07:43:16
0次
这个程序哪里错了?
for (a=97,b=97; a<=122,b<=122; a++,b++)
{
letter[a]=a;
count[b]=b;
printf("字母[%c]对应的ASCALL码值是:%d\n",letter[a],count[b]);
printf("\n");
}
for循环没有将循环体用花括号扩起来
程序是输出所有字母的ASC码吧,错的地方挺多,而且程序思路也不好,简单分析下:
#include
void main()
{
char letter[26]; //记录字母的数组
int count[26];//记录字母对应ASC码
int a,b;
for (a=97,b=97; a<=122,b<=122; a++,b++)//for循环内循环语句没括起来吧?
letter[a]=a;//你的letter大小才26,而a的范围是97到122啊
count[b]=b;//同上
printf("字母[%c]对应的ASCALL码值是:%d\n",letter[a],count[b]);
printf("\n");
}
按你的题先写的程序:
#include
int main()
{
int i;
for (i=97; i<=122; i++)
printf("字母[%c]对应的ASCALL码值是:%d\n",i,i);
printf("\n");
}
很简单吧,当把一个整型值以字符型输出,它会直接输出整型量对应的字符,就这么简单。
#include
void main()
{
char letter[26];
int count[26];
int a,b;
for (a=0,b=0;a<26;a++,b++){
letter[a]=97+a;
//count[b]=97;
printf("字母[%c]对应的ASCALL码值是:%d\n",letter[a],letter[a]);
printf("\n");
}
}
相关内容