Print English Alphabet in C

Exercise:

Write a C Program to print English alphabets.

1. Print uppercase letters

Click Here to View the Solution!
#include <stdio.h>        
int main() {
    char ch;
    for (ch = 'A'; ch <= 'Z'; ++ch) {
        printf("%c ", ch);
    }
    return 0;
}       
Click Here to View the Output!
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
Click Here to View the Explanation!
  • This program is used to display all the alphabets from A to Z using a for loop.
  • In the main method, a character variable c initialized.
  • In a for loop, a condition is set which will keep iterating until the ch becomes less than or equal to Z by each time incrementing ch by one.
  • After each iteration a character will be printed.
  • All the English alphabets will be displayed in uppercase.
  • The return 0 statement is used to exit the program execution.

2. Print both uppercase or lowercase letter

Click Here to View the Solution!
#include <stdio.h>
int main() {
    char ch;
    printf("Enter U to display uppercase alphabets.\n");  
    printf("Enter L to display lowercase alphabets. \n");
    scanf("%c", &ch);
    if (ch == 'U' || ch == 'u') {
        for (ch = 'A'; ch <= 'Z'; ++ch)
            printf("%c ", ch);
    }

    else if (ch == 'L' || ch == 'l') {
        for (ch = 'a'; ch <= 'z'; ++ch)
            printf("%c ", ch);
    }

    else {
        printf("Error! You entered an invalid character.");
    }
    return 0;
}
Click Here to View the Output!
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
Click Here to View the Explanation!
  • This program is used to display both the uppercase and lowercase alphabets using if...else statements.
  • A character variable ch is initialized.
  • The program requests the user to enter either u or l depending on the user’s choice of whether they want to display uppercase or lowercase alphabets and store the choice in the variable ch using the scanf() function.
  • If the user enters either U or u, the first if statement will be executed which will print only the uppercase alphabets from A to Z.
  • If the user enters either L or l, the if…else statement will be executed which will print only the lowercase alphabets from a to z.
  • If the user enters any letter besides u and l, an error message will be displayed.
  • The return 0 statement is used to exit the program execution.