你这个程序的缺陷在于:
当两个字母一个是大写,一个是小写时无法正常输出
所以,我们要对一个是大写,一个是小写的情况做特殊处理
使两者一致
在循环开始之前加入以下代码:
if(Thefirstnumber>='a'&& Thefirstnumber<='z'&&Thesecordnumber>='A'&& Thesecordnumber<='Z')
Thesecordnumber = Thesecordnumber + 32;
//如果第一个是小写,第二个是大写,把第二个改为小写
if(Thefirstnumber>='A'&& Thefirstnumber<='Z'&&Thesecordnumber>='a'&& Thesecordnumber<='z')
Thesecordnumber = Thesecordnumber - 32;
//如果第一个是大写,第二个是小写,把第二个改为大写
这里改为大写小写均可,你后面的循环可以自适应,只需两者一致即可
改这样就行了
#include
int main()
{
int i;
char Thefirstnumber;
char Thesecordnumber;
printf("任意输入两个英文:");
scanf("%c %c",&Thefirstnumber,&Thesecordnumber);
if (Thefirstnumber >= 'a' && Thefirstnumber <= 'z')
{
Thefirstnumber = Thefirstnumber - 'a' + 'A';
}
if (Thesecordnumber >= 'a' && Thesecordnumber <= 'z')
{
Thesecordnumber = Thesecordnumber - 'a' + 'A';
}
for(i=Thefirstnumber + 1; i
printf("%c ",i);
}
return 0;
}
#include
bool small(char x)//判断是否小写字母
{
return x>='a'&&x<='z';
}
int main()
{
int i;
char Thefirstnumber;
char Thesecordnumber;
printf("任意输入两个英文:");
scanf("%c %c",&Thefirstnumber,&Thesecordnumber);
if(small(Thefirstnumber))Thefirstnumber=Thefirstnumber-'a'+'A';//小写转大写
if(small(Thesecordnumber))Thesecordnumber=Thesecordnumber-'a'+'A';
if(Thefirstnumber>Thesecordnumber)//交换
{
i=Thesecordnumber;
Thesecordnumber=Thefirstnumber;
Thefirstnumber=i;
}
for(i=Thefirstnumber+1;i
printf("%c\n",i);
}
return 0;
}
very good