C Program to Display Characters from A to Z both in Uppercase and Lowercase using Loop

@codevarsity
 · 
2.1k views
 · 

A simple C program to print characters from A to Z using loop.

Code

#include <stdio.h>
int main()
{
    char c;

    printf("Enter u to display alphabets in uppercase. And enter l to display alphabets in lowercase: ");
    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! You entered invalid character.");
    return 0;
}

Output

Enter u to display alphabets in uppercase. And enter l to display alphabets in lowercase: 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 

Comments