WAP to print all alphabet from a to z.

C Program to Display Characters from A to Z Using Loop
You will learn to display the English alphabets using for loop in this example.

To understand this example, you should have the knowledge of following C programming topics:
  • C if, if...else and Nested if...else Statement
  • C Programming while and do...while Loop
Example #1: Program to Display English Alphabets
#include <stdio.h>
int main()
{
    char c;

    for(c = 'A'; c <= 'Z'; ++c)
       printf("%c ", c);
   
    return 0;
}
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
In this program, the for loop is used to display the English alphabets in uppercase.
Here's a little modification of the above program to display the English alphabets in either uppercase or lowercase depending upon the input from the user.
Example #2: Program to Display English Alphabets in Uppercase and Lowercase
#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

  1. Write a C program to print all alphabets from a to z using for loop.

    Code of given problem:

    int main()
    {
    int i;
    printf("List of alphabet from a to z:");
    for(i=97;i<=122;i++)
    {
    printf(" %c ",i);
    }
    return 0;
    }

    Very informative blog!

    Please take some time to visit my blog @
    for loop program examples

    Thanks!

    ReplyDelete

Post a Comment

Most Viewed

Write C program to enter any year and check whether year is leap year or not using conditional/ternary operator.

WAP to input week number and print week day name.

C Program to Find Third Angle of a Triangle