从键盘输入一个字符,可以是数字、字母、或是标点符号,对输入的字符进行判断,如果是数字则输出“* is a number!”,如果是字母则输出“* is a letter!”,如果是其他的字符怎输出“* is the other!”(*为输入的字符)。
2条回答 默认 最新
- CSDN专家-link 2022-03-30 15:38关注
判断ASCII码范围就可以了
//从键盘输入一个字符,可以是数字、字母、或是标点符号,对输入的字符进行判断,如果是数字则输出“* is a number!”,如果是字母则输出“* is a letter!”,如果是其他的字符怎输出“* is the other!”(*为输入的字符)。 #include <iostream> using namespace std; int main() { char ch; cin>>ch; if(ch >= '0' && ch <='9') cout<<ch<<" is a number!"; else if((ch >= 'a' && ch <= 'z') || (ch>='A' && ch <= 'Z')) cout<<ch<<" is a letter!"; else cout<<ch<<" is the other!"; return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用