VOOZH about

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

⇱ C Program to Print Continuous Character Pattern - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Program to Print Continuous Character Pattern

Last Updated : 7 Aug, 2022

Here, we will see how to print continuous character patterns using a C program. Below are the examples:

Input: rows = 5
Output:  


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

Input: rows = 3
Output:


B C 
D E F 

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

  1. Using for loop.
  2. Using while loop.

Let's discuss each of these in detail.

1. Using for loop

Approach 1: Using Character

  1. Assign any character to one variable for the printing pattern. 
  2. The first for loop is used to iterate the number of rows.
  3. The second for loop is used to repeat the number of columns. 
  4. 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 

Approach 2:  Converting a given number into a character

  1. Assign any number to one variable for the printing pattern. 
  2. The first for loop is used to iterate the number of rows.
  3. The second for loop is used to repeat the number of columns. 
  4. After entering into the loop convert the given number in to 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 

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 given no of rows

Auxiliary space: O(1)

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(n2) where n is given rows

Auxiliary Space: O(n)

Comment
Article Tags: