English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structures

C Language Files

C Others

C Language Reference Manual

C program uses loops to display characters from A to Z

Comprehensive Collection of C Programming Examples

In this example, you will learn to print all the letters of the English alphabet.

To understand this example, you should be familiar with the followingC Programming LanguageTopic:

The program prints English letters

#include <stdio.h>
int main() {
    char c;
    for (c = 'A'; c <= 'Z'; ++c)
        printf("%c ", c);
    return 0;
}

Output Result

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

In this program, the for loop is used to display English letters in uppercase.

These are some modifications to the above program. The program displays English letters in uppercase or lowercase based on the user's input.

Print lowercase/Uppercase letters

#include <stdio.h>
int main() {
    char c;
    printf("Enter u to display uppercase letters.\n");
    printf("Enter l to display lowercase letters. \n");
    scanf("%c", &c);
    if (c == 'U' || c == 'u') {
        for (c = 'A'; c <= 'Z'; ++c)
            printf("%c ", c);
    }
        for (c = 'a'; c <= 'z'; ++c)
            printf("%c ", c);
    }
        printf("Error! You entered an invalid character.");
    }
    return 0;
}

Output Result

Enter u to display uppercase letters.
Enter l to display lowercase letters.
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

Comprehensive Collection of C Programming Examples