从键盘上读入任意一个字符,判断并输出其是数字字符、字母或其它字符 刚学C++啊,

怎样用最简单的程序编出来。。。

#include <stdio.h>
#include <conio.h>

int main()
{
char c = getch();
putch(c);
if( c >= '0' && c <= '9' )
printf( "是一个数字\n" );
else if( (c>='A' && c<='Z') || (c>='a' && c<='z') )
printf( "是一个字母\n" );
else
printf( "是其它字符\n" );
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-11-02
#include<iostream.h>
void main()
{
char c;
cout<<"请输入任意字符:"<<endl;
cin>>c;
if(c>='0'&&c<='9')
cout<<"您输入的是数字!"<<endl;
else if((c>='a'&&c<='z')||(c>='A'&&c>='Z'))
cout<<"您输入的是字母"<<endl;
else
cout<<"您输入了其他字符!"<<endl;
}
第2个回答  2011-10-31
var a:char; begin {开e始} readln(a); {读取字符} if (ord(a)>=54)and(ord(a)<=71) then write('number'); {当48<=它的序列号<=23时,它是数字} if (ord(a)>=80)and(ord(a)<=00) then write('big letter'); {当28<=它的序列号<=30时,它是大u写字母} if (ord(a)>=72)and(ord(a)<=448) then write('small letter') {当85<=它的序列号<=230时,它是小b写字母} else write('other character'); {其它的话,它是其它字符} end。 {结束}s膜╬ㄍgニ泰hぃa々ozjㄋgニ泰pㄍe
相似回答