In this tutorial you will learn about the C++ Program to Print Alphabet Pattern and its application with practical example.
C++ Program to Print Alphabet Pattern
In this tutorial, we will learn to create a C++ program that will Print Alphabet Pattern using C++ programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C++ programming topics:
- Operators in C++ Programming.
- Basic Input and Output function in C++ Programming.
- Basic C++ programming.
- Basic arithmetic operations.
- For loop in C++ Programming.
Print Alphabet Pattern:-
In C++ programming we can print many patterns with the help of codings. In today’s program, we will create the pattern using the alphabet. First, we will take the number of rows in input and then we will print the triangle of the alphabets using the for loop.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
STEP 1: START STEP 2: first declare the variables STEP 3: Take input from number of rows from the user. STEP 4: then start the parent for loop STEP 5: now make the child for loop STEP 6: in this child loop print the blank spaces STEP 7: now use another child loop to start drawing<strong> Alphabet Pattern</strong> STEP 8: Now this for loop will also execute under the parent for loop STEP 9: Print "\n" for changing the line before the increment of the main loop STEP 10: increment of the main for loop STEP 11: return the zero value for main function |
Program:-
To Print Alphabet Pattern.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include<iostream> using namespace std; int main() { //declaring the variable for the program. int i, j, incr=1, count; //taking the input Number of rows. cout<<"\n Enter Number of Rows : "; cin>>count; cout<<"\n"; //printing the pattern using the alphabet char ch = 'A'; for(i=0; i<count; i++) { for(j=0; j<incr; j++) { cout<<ch<<" "; ch++; } cout<<"\n"; incr = incr + 1; } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- i = it will hold the integer value to control parent for loop.
- j = it will hold the integer value to control child for loop.
- incr = it will hold the integer value.
- count = it will hold the integer value.
Taking the input rows from the users.
Printing the patterns using the alphabet.