‘A’ to ‘Z’
. We have a char type variable ch, which is initialized with the value ‘A’
and incremented by 1
on every loop iteration. At every loop iteration, the value of ch is printed. The loop ends when the variable ch prints ‘Z
’.#include <stdio.h>
int main() {
char ch;
//Print characters from 'A' to 'Z'
for (ch = 'A'; ch <= 'Z'; ++ch)
//there is a whitespace after %c so that the
//characters have spaces in between.
printf("%c ", ch);
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
‘A’ to ‘Z’
in lowercase. The logic is same as first example. Here ch is initialized with value ‘a’
and the loop ends when the condition ch <= 'z'
meets.#include <stdio.h>
int main() {
char ch;
//Print characters from 'a' to 'z'
for (ch = 'a'; ch <= 'z'; ++ch)
printf("%c ", ch);
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