C Program to Print Continuous Character Pattern
Last Updated :
07 Aug, 2022
Here, we will see how to print continuous character patterns using a C program. Below are the examples:
Input: rows = 5
Output:
A
B C
D E F
G H I J
K L M N O
Input: rows = 3
Output:
A
B C
D E F
There are 2 ways to print continuous character patterns in C:
- Using for loop.
- Using while loop.
Let's discuss each of these in detail.
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:
C
// C program to print continuous
// character pattern using
// character
#include <stdio.h>
int main()
{
int i, j;
// Number of rows
int rows = 3;
// Taking first character of alphabet
// which is useful to print pattern
char character = 'A';
// This loop is used to identify
// number rows
for (i = 0; i < rows; i++)
{
// This for loop is used to
// identify number of columns
// based on the rows
for (j = 0; j <= i; j++)
{
// Printing character to get
// the required pattern
printf("%c ",character);
// Incrementing character value so
// that it will print the next character
character++;
}
printf("\n");
}
return 0;
}
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 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:
C
// C program to print continuous
// character pattern by converting
// number in to character
#include <stdio.h>
// Driver code
int main()
{
int i, j;
// Number of rows
int rows = 5;
// Given a number
int number = 65;
// This loop is used to identify
// number of rows
for (i = 0; i < rows; i++)
{
// This loop is used to identify number
// of columns based on the rows
for (j = 0; j <= i; j++)
{
// Converting number in to character
char character = (char)(number);
// Printing character to get the
// required pattern
printf("%c ", character);
// Incrementing number value so
// that it will print the next
// character
number++;
}
printf("\n");
}
return 0;
}
OutputA
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:
C
// C program to print the continuous
// character pattern using while loop
#include <stdio.h>
// Driver code
int main()
{
int i = 1, j = 0;
// Number of rows
int rows = 5;
// Given a character
char character = 'A';
while (i <= rows)
{
while (j <= i - 1)
{
// Printing character to get
// the required pattern
printf("%c ",character);
j++;
// Incrementing character value
// so that it will print the next
// character
character++;
}
printf("\n");
j = 0;
i++;
}
return 0;
}
OutputA
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:
C
// C program to print continuous
// character pattern by converting
// number in to character
#include <stdio.h>
// Driver code
int main()
{
int i = 1, j = 0;
// Number of rows
int rows = 5;
// Given a number
int number = 65;
while (i <= rows)
{
while (j <= i - 1)
{
// Converting number in to character
char character = (char)(number);
// Printing character to get the
// required pattern
printf("%c ",character);
j++;
// Incrementing number value so
// that it will print the next
// character
number++;
}
printf("\n");
j = 0;
i++;
}
return 0;
}
OutputA
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)
Similar Reads
Pattern Programs in C Printing patterns using C programs has always been an interesting problem domain. We can print different patterns like star patterns, pyramid patterns, Floyd's triangle, Pascal's triangle, etc. in C language. These problems require the knowledge of loops and if-else statements.We will discuss the fo
15+ min read
C Program For Printing Right Half Pyramid Pattern A half-right pyramid consists of rows with sequential stars, numbers or characters arranged in a triangular shape. The first row has one character, the second row has two, and so on. The characters are aligned to the left making it similar to the right-angle triangle. In this article, we will learn
5 min read
C Program to Print Pyramid Pattern In C, a pyramid pattern consists of numbers, stars, or alphabets arranged in a triangular shape. In this article, we will learn how to print different shapes of pyramid patterns using C program.Following are the 6 common pyramid patterns:Right Half Pyramid PatternRight half pyramid pattern looks lik
13 min read
C Program to Print Number Pattern A number pattern involves printing numbers in a specific arrangement or shape, often in the form of a pyramid, triangle, or other geometric shapes. They are great for practicing loops and conditional statements. In this article, we will learn how to print different number patterns in C.Rhombus Numbe
6 min read
C Program to Print Continuous Character Pattern Here, we will see how to print continuous character patterns using a C program. Below are the examples: Input: rows = 5Output: A B C D E F G H I J K L M N O Input: rows = 3Output: A B C D E F There are 2 ways to print continuous character patterns in C: Using for loop.Using while loop. Let's discuss
5 min read
C Program To Print Character Pyramid Pattern Pyramid patterns is a classic logical programming exercise where a triangular looking pattern is printed by treating the output screen as a matrix and printing a given character. In this article, we will explore how to print various alphabet pyramid patterns using C program.Half Pyramid PatternHalf
4 min read
C Program to Print Right Half Pyramid Pattern The Right Half Pyramid Pattern is a triangular pattern consists of rows where each row contains an increasing number of characters. The number of characters starts from 1 and increases by 1 in each subsequent row. Characters are aligned to the left, resembling a right-angle triangle with its hypoten
2 min read
C Program To Print Hollow Pyramid Patterns The Hollow Pyramid patterns are the variation of pyramid patterns where only the outer edges are filled with characters but the interior is left empty. In this article, we will learn how to print different hollow pyramid patterns.There can be 5 hollow pyramid patterns corresponding to each of the no
12 min read
C Program to Print Cross or X Pattern The Cross or X Pattern is a pattern where characters or stars are printed diagonally from top-left to bottom-right and from top-right to bottom-left, forming an "X" shape. In this article, we will learn how to print this pattern using a C program. Program to Print Cross or X PatternStar Cross#includ
3 min read
Programs to print Interesting Patterns Program to print the following pattern: Examples : Input : 5Output:* * * * * * * * * ** * * * * * * ** * * * * ** * * ** ** ** * * ** * * * * ** * * * * * * ** * * * * * * * * *This program is divided into four parts.C++// C++ program to print // the given pattern #include<iostream> using name
15+ min read