VOOZH about

URL: https://www.geeksforgeeks.org/c/c-program-to-print-continuous-character-pyramid-pattern/

⇱ C Program To Print Continuous Character Pyramid Pattern - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Program To Print Continuous Character Pyramid Pattern

Last Updated : 22 Sep, 2022

There are 2 ways to print continuous character patterns in C i.e:

  1. Using for loop
  2. Using while loop

Input: 

rows = 5

Output:  

A 
B C 
D E F 
G H I J 
K L M N O

1. Using for loop

Approach 1: Using Character

  • Assign any character to one variable for the printing pattern. 
  • The first for loop is used to iterate the number of rows.
  • The second for loop is used to repeat the number of columns. 
  • Then print the character based on the number of columns and increment the character value at each column to print a continuous character pattern.

Below is the C program to print continuous character patterns using character using for loop: 


Output
A 
B C 
D E F 

Time complexity: O(R*R) where R is the given number of rows.
Auxiliary space: O(1), as constant space is being used.

Approach 2:  Converting a given number into a character

  • Assign any number to one variable for the printing pattern. 
  • The first for loop is used to iterate the number of rows.
  • The second for loop is used to repeat the number of columns. 
  • After entering into the loop convert the given number into character to print the required pattern based on the number of columns and increment the character value at each column to print a continuous character pattern.

Below is the C program to print continuous character patterns by converting numbers into a character:


Output
A 
B C 
D E F 
G H I J 
K L M N O 

Time complexity: O(R*R) where R is the given number of rows.
Auxiliary space: O(1), as constant space is being used.

2. Using while loop:

Approach 1: Using character

The while loops check the condition until the condition is false. If the condition is true then enter into a loop and execute the statements. Below is the C program to print continuous character patterns using character:


Output
A 
B C 
D E F 
G H I J 
K L M N O 

Time complexity: O(R*R) where R is the given number of rows.
Auxiliary space: O(1), as constant space is being used.

Approach 2: Converting a given number into a character

Below is the C program to print a continuous character pattern by converting a given number into a character using a while loop:


Output
A 
B C 
D E F 
G H I J 
K L M N O 

Time complexity: O(R*R) where R is the given number of rows.
Auxiliary space: O(1), as constant space is being used.

Comment
Article Tags: