Alphabet

C program to print all upper case and lower case Alphabets

C program to print all upper case and lower case Alphabets

In this article, we will discuss the concept of C program to print all upper case and lower case Alphabets

In this post, we are going to learn how to display the upper case(A to Z) and lower case (a to z) Alphabets using loops on C programming language

Alphabets

C code to display all upper case and lower case Alphabets

Code to display all the Alphabets using for loop

The program displays all the upper case and lower case alphabet letters from a to z using for loop in C language

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;//char variable declaration
//Printing upper case Alphabets
printf("Uppercase Alphabets are: \n");
for(ch='A'; ch<='Z'; ch++){
printf("%c",ch);
printf(" ");
//display uppercase Alphabets with space
}
printf("\n");//move to next line

//Printing lower case Alphabets
printf("\nLowercase Alphabets are: \n");
for(ch='a'; ch<='z'; ch++){
printf("%c",ch);
printf(" ");
//display lowercase Alphabets with space
}

    //printf("Hello world!\n");
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Output 1

In the above program, we are using two for loops, one is used to print upper case Alphabet letters and another to print lower case Alphabet letters.

 

Code to display all Alphabets using while loop

The program displays all the upper case and lower case alphabets letters from a to z using while loop in C language

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;//char variable declaration
//Printing upper case Alphabets
printf("Uppercase Alphabets are: \n");
ch='A';
while(ch<='Z'){
printf("%c",ch);
printf(" ");
//display uppercase Alphabets with space
 ch++;
}
printf("\n");//move to next line

//Printing lower case Alphabets
printf("\nLowercase Alphabets are: \n");
ch='a';
while(ch<='z'){
printf("%c",ch);
printf(" ");
//display lowercase Alphabets with space
ch++;
}

    //printf("Hello world!\n");
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Output 2

In the above program, we are using two while loops, one is used to print upper case letters and another to print lower case letters

Code to display all  Alphabets using do-while loop

The program displays all the upper case and lower case alphabets letters from a to z using do-while loop in C language

Program 3

 

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;//char variable declaration
//Printing upper case Alphabets
printf("Uppercase Alphabets are: \n");
ch='A';
do{
printf("%c",ch);
printf(" ");
//display uppercase Alphabets with space
 ch++;
}while(ch<='Z');
printf("\n");//move to next line

//Printing lower case Alphabets
printf("\nLowercase Alphabets are: \n");
ch='a';
do{
printf("%c",ch);
printf(" ");
//display lowercase Alphabets with space
ch++;
}while(ch<='z');

    //printf("Hello world!\n");
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Output 3

In the above program, we are using two do-while loops, one is used to print upper case letters and another to print lower case letters

 

Approach

  • We will declare a counter variable “ch” of the loop (for loop, while loop and do-while loop) and initialize it by “a”(for print lower case) or “A” (for print upper case);
  • The program checks the given condition(ch<=”z” (lower case) or ch<=”Z”(Upper case). If the condition is true, alphabets will be printed
  • if the condition is false – loops will be terminated

 

Suggested for you

for loop in C language

while loop in C language

do-while loop in C language

 

Similar post

Java program to print all upper case and lower case Alphabets

C++ program to print all upper case and lower case Alphabets

C program to print all upper case and lower case Alphabets

 

Java code to print all upper case and lower case Alphabets between the given range

C++ code to print all upper case and lower case Alphabets between the given range

C code to print all upper case and lower case Alphabets between the given range

 

Java program to print all upper case and lower case Alphabets
Program to Display all Alphabet between given range using loops in Java
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago