A Simple C Program That Prints The Alphabet in Lowercase And Uppercase

A Simple C Program That Prints The Alphabet in Lowercase And Uppercase

Print the Alphabet in Lowercase and Uppercase Using Only putchar()

Play this article

Introduction

Alphabets are simply letters from a to z, which could be in uppercase (capitalized) or in lowercase.

How to Generate and Print All Alphabet in Lowercase followed by an Uppercase

To achieve this, we are going to be using the putchar() function to print the alphabet to standard output.

We will first use the loop, which could be a while or a for loop, but in this tutorial, we are going to be using the while loop, to print first the lowercase alphabets, then followed by the uppercase alphabet then finally with a new line character at the end.

I am going to be using the Betty style of coding in C:

#include <stdio.h>
/**
  *main - prints lowercase followed by uppercase alphabets
  *Return: 0
*/
int main(void)
{
    char lowercase, uppercase;

    lowercase = 'a';
    uppercase = 'A';

    while (lowercase <= 'z')
    {
        putchar(lowercase);
        lowercase++;
    }
    while (uppercase <= 'Z')
    {
        putchar(uppercase);
        uppercase++;
    }
    putchar('\n');
    return (0);
}

You can now compile and run the code, which will give you a result that is similar to the image below:

Conclusion

This method is just one of the numerous ways out there of printing alphabets in lowercase followed by uppercase.

Thank you for reading, you can connect with me on Twitter and LinkedIn.