C,该怎么解决
C
#include"stdio.h"
main()
{
char c1,c2;
printf("\nplease input the first character:\n");
c1=getchar();
printf("\nplease input the second character:\n");
c2=getchar();
if(((c1>=65&&c1<=90)||(c1>=97&&c1<=122))&&((c2>=65&&c2<=90)||(c2>=97&&c2<=122)))
printf("\ntwo character are both char!\n");
elseif(((c1>=65&&c1<=90)||(c1>=97&&c1<=122))&&(c2>=48&&c2<=57))
printf("\nthe first input is character;the second input is num!\n");
elseif((c1>=48&&c1<=57)&&((c2>=65&&c2<=90)||(c2>=97&&c2<=122)))
printf("\nthe first input is num;the second input is character!\n");
elseif((c1>=48&&c1<=57)&&(c2>=48&&c2<=57))
printf("\nthe two input are both num!\n");
else
printf("\nInput error!please input again\n");
}
输出错误,请各位指点!
------解决方案--------------------
#include"stdio.h"
main()
{
char c1,c2;
printf("\nplease input the first character:\n");
c1=getchar();
printf("\nplease input the second character:\n");
c2=getchar();
if(((c1>=65&&c1<=90)||(c1>=97&&c1<=122))&&((c2>=65&&c2<=90)||(c2>=97&&c2<=122)))
printf("\ntwo character are both char!\n");
elseif(((c1>=65&&c1<=90)||(c1>=97&&c1<=122))&&(c2>=48&&c2<=57))
printf("\nthe first input is character;the second input is num!\n");
elseif((c1>=48&&c1<=57)&&((c2>=65&&c2<=90)||(c2>=97&&c2<=122)))
printf("\nthe first input is num;the second input is character!\n");
elseif((c1>=48&&c1<=57)&&(c2>=48&&c2<=57))
printf("\nthe two input are both num!\n");
else
printf("\nInput error!please input again\n");
}
输出错误,请各位指点!
------解决方案--------------------
#include<stdio.h>
int main()
{
char c1,c2;
printf("\nplease input the first character:\n");
c1=getchar();
while(getchar()!='\n');//加上这句把换行符读掉。。
printf("\nplease input the second character:\n");
c2=getchar();
if(((c1>=65&&c1<=90)
------解决方案--------------------
(c1>=97&&c1<=122))&&((c2>=65&&c2<=90)
------解决方案--------------------
(c2>=97&&c2<=122)))
printf("\ntwo character are both char!\n");
else if(((c1>=65&&c1<=90)
------解决方案--------------------
(c1>=97&&c1<=122))&&(c2>=48&&c2<=57))//else跟if别粘在一起。。
printf("\nthe first input is character;the second input is num!\n");
else if((c1>=48&&c1<=57)&&((c2>=65&&c2<=90)
------解决方案--------------------
(c2>=97&&c2<=122)))
printf("\nthe first input is num;the second input is character!\n");
else if((c1>=48&&c1<=57)&&(c2>=48&&c2<=57))
printf("\nthe two input are both num!\n");
else printf("\nInput error!please input again\n");
}