#include <stdlib.h>
int main()
{
char c;
scanf("%c", &c);
if((c <= 'A') || (c >= 'Z'))
{
printf("非大寫字母.\n");
}
else
{
c = c + 32;
printf("%c %d\n", c, c);
}
return 0;
}如果是輸入小寫字母輸出大寫字母呢?
這個(gè)需要知道小寫字母和大寫字母在ASCII碼的大小就行了
A 65 Z 90
a 97 z 116
大寫轉(zhuǎn)小寫是+32,小寫轉(zhuǎn)大寫-32就可以了
#include <stdio.h>
#include <stdlib.h>
int main()
{
char c;
scanf("%c", &c);
if((c <= 'a') || (c >= 'z'))
{
printf("非大寫字母。\n");
}
else
{
c = c - 32;
printf("%c %d\n", c, c);
}
return 0;
}