打印英文字母的程序
#include <stdio.h>
int main() {
char c;
for (c = 'A'; c <= 'Z'; ++c)
printf("%c ", c);
return 0;
}
输出
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
在此程序中,使用for
循环显示大写英文字母。
对上述程序进行一点修改。该程序根据用户输入的英文字母显示大写或小写。
打印小写/大写字母
#include <stdio.h>
int main() {
char c;
printf("Enter u to display uppercase alphabets.\n");
printf("Enter l to display lowercase alphabets. \n");
scanf("%c", &c);
if (c == 'U' || c == 'u') {
for (c = 'A'; c <= 'Z'; ++c)
printf("%c ", c);
} else if (c == 'L' || c == 'l') {
for (c = 'a'; c <= 'z'; ++c)
printf("%c ", c);
} else {
printf("Error! You entered an invalid character.");
}
return 0;
}
输出
Enter u to display uppercase alphabets. Enter l to display lowercase alphabets. l a b c d e f g h i j k l m n o p q r s t u v w x y z