BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to Display Characters from A to Z Using Loop

By Chaitanya Singh | Filed Under: C Programs

In this guide, you will learn how to write a C program to display the characters from ‘A’ to ‘Z’ using loop.

Example 1: Program to print characters from ‘A’ to ‘Z’ using loop

In this example, we are using a for loop to print alphabets from ‘A’ to ‘Z’. We have a char type variable ch, which is initialized with the value ‘A’ and incremented by 1 on every loop iteration. At every loop iteration, the value of ch is printed. The loop ends when the variable ch prints ‘Z’.

#include <stdio.h>
int main() {
  char ch;
  //Print characters from 'A' to 'Z'
  for (ch = 'A'; ch <= 'Z'; ++ch)
    //there is a whitespace after %c so that the
    //characters have spaces in between.
    printf("%c ", ch);
  return 0;
}

Output:
C Program to Display Characters from A to Z Using Loop

Example 2: Print A to Z in lowercase: ‘a’ to ‘z’

Similarly, you can print ‘A’ to ‘Z’ in lowercase. The logic is same as first example. Here ch is initialized with value ‘a’ and the loop ends when the condition ch <= 'z' meets.

#include <stdio.h>
int main() {
  char ch;
  //Print characters from 'a' to 'z'
  for (ch = 'a'; ch <= 'z'; ++ch)
    printf("%c ", ch);
  return 0;
}

Output:
C Program to Display Characters from a to z Using Loop

Related C Examples:

  • C Program to find LCM of two integers
  • C Program to find GCD of two integers
  • C Program to display multiplication table
  • C Program to add two numbers
❮ C TutorialC Programs ❯

Programs

  • C Programs
  • Java Programs
  • C++ Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap