C Program to Print Alphabets From A to Z - Using a Loop

Print Alphabets From A to Z Using a Loop

#include <stdio.h>

int main() {
    // Declare a character variable to iterate through alphabet
    char c;

    // Loop from 'A' to 'Z'. Each iteration increments the character.
    for (c = 'A'; c <= 'Z'; ++c) {
        printf("%c ", c);  // Print the current letter followed by a space
    }

    // Print a newline at the end for a clean output
    printf("\n");

    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
        

In C, characters are stored using their ASCII values. The uppercase letters 'A' through 'Z' are consecutive, so you can use a for-loop to iterate from 'A' to 'Z' and print each letter. Once you understand this, you can easily adapt the loop to print lowercase letters or any other range of characters.


Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...