C Program to Print the Lowercase Alphabet in Reverse

C Program to Print the Lowercase Alphabet in Reverse

A C program that prints the lowercase alphabet in reverse, using only the putchar() function.

Play this article

Introduction

In this article, you are going to learn how to print to standard output all the alphabet but this time around in reverse.

We are simply going to loop through all the alphabet while printing them out one after the other, but instead of in an ascending order starting from a, we will be doing that in a descending order starting from z.

How To Print the Lowercase Alphabets in Reverse

We are going to be using the putchar() function as well as the while loop inorder to achieve this. The C style used is the Betty style.

#include <stdio.h>
/**
  *main - prints alphabets in reverse
  *Return: 0
*/
int main(void)
{
    char ch;

    ch = 'z';

    while (ch >= 'a')
    {
        putchar(ch);
        ch--;
    }
    putchar('\n');
    return (0);
}

You should get something similar to what is in the image below.

Conclusion

Amongst the method of doing this, this is one of the most straightforward methods.

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