Skip to main content

ProwessApps

Learn · Practice · Excel

C Program to print Pattern 3 A A B A B C A B C D A B C D E

C Code Example — Pattern Programs

ADVERTISEMENT

C Program to print Pattern 3 A A B A B C A B C D A B C D E

Objective

Write a C program to print a left-aligned right triangle of Characters.

Algorithm / Approach

  1. Run an outer loop using character variables: i = 'A' to 'E'.
  2. Run an inner loop: j = 'A' to i.
  3. Inside the inner loop, print the current character j using the %c format specifier.
  4. Print a newline.
main.c
#include<stdio.h>
int main( ) {
 char i,j;
 for(i='A';i<='E';i++) {
  for(j='A';j<=i;j++) {
   printf("%c ",j);
  }
  printf("\n");
 }
 return 0;
}

Expected Output

A
A B
A B C
A B C D
A B C D E

Explanation of the Program

  • In C, characters (char) are actually just small integers under the hood, representing their ASCII values (e.g., 'A' is 65).
  • Because they are integers, you can use them directly in for loops! The loop will iterate from 65 to 69, printing the corresponding letters perfectly.

Complexity

Time Complexity O(n^2)
Space Complexity O(1)
ADVERTISEMENT