循環輸出 26 個字母。
#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
實例 - 輸出大寫或小寫字母
#include <stdio.h> int main() { char c; printf("輸入 u 顯示大寫字母,輸入 l 顯示小寫字母: "); 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! 輸入非法字符。"); return 0; }
輸入 u 顯示大寫字母,輸入 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