Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

C Alphabet Pattern 8

Posted in C Tutorial
Updated on Jan 10, 2024
By Mari Selvan
👁️ 100 - Views
⏳ 4 mins
💬 1 Comment
C Alphabet Pattern 8

Photo Credit to CodeToFun

C Alphabet Pattern 8

Here`s a program that prints the above alphabet pattern using C Programming:

example.c
Copied
Copy To Clipboard
#include <stdio.h>
int main()
{
 int i, j;
 for(i=65; i<=69; i++)
 {
  for(j=69; j>=i; j--)
   printf("%c", j);
  printf("\n");
 }
 return 0;
}

💻 Testing the Program

When you run the above program, it will print the following output:

Output
EDCBA
EDCB
EDC
ED
E

🧠 How the Program Works

Let's break down the logic behind the code:

  • The program starts by including the stdio.h header file, which provides input/output functions such as printf.
  • Inside the main function, two variables i and j are declared to be used as loop counters.
  • The outer for loop runs from i = 65 to i <= 69. The ASCII value of 'A' is 65, and 'E' is 69, so the loop iterates five times, representing the five rows of the pattern.
  • Within each iteration of the outer loop, the inner for loop runs from j = 69 to j >= i. The ASCII value of 'E' is 69, and it decrements by one in each iteration, printing the letters in a decreasing sequence.
  • The %c format specifier is used with printf to print the characters based on their ASCII values.
  • After printing the required number of letters for the current row, a newline character \n is printed to move to the next line.
  • This process repeats until all rows are printed.
  • Finally, the main function returns 0 to indicate successful program execution.

Each row contains a decreasing sequence of letters, starting from 'E' and ending with 'A'. The number of letters in each row corresponds to the row number, with the first row having five letters and the last row having only one letter.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mari Selvan
Mari Selvan
11 months ago

If you have any doubts regarding this article (C Alphabet Pattern 8) please comment here. I will help you immediately.

We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy