Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! π πΉLearn advanced coding techniques in C& C++ πΉMaster Linux internals & shell scripting πΉDeep dive into Data Structures & Algorithms πΉExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) πΉGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C++ Triangle Pattern Programs 3: Star, Number, Alphabet & Binary Patterns with Output
C++ Program to Print Right-Aligned Star Triangle Pattern
Source Code
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter the number:"<<endl;
cin>>num;
for(int i=1;i<=num;i++)
{
for(int k=num;k>=i;k--)
{
cout<<" ";
}
for(int j=1;j<=i;j++)
{
cout<<"* ";
}
cout<<endl;
}
}
Expected Output
Enter the number:
5
*
* *
* * *
* * * *
* * * * *
Explanation
This C++ program prints a right-aligned star triangle pattern using nested loops. The outer loop controls the number of rows, while the first inner loop prints spaces before the stars.
The first inner loop runs from num down to i and prints two spaces in each iteration. This creates the alignment of the triangle. The second inner loop prints * characters, and the number of stars increases by one in every row.
Algorithm
- Start the program.
- Read the number of rows from the user.
- Run an outer loop from
i = 1tonum. - Use the first inner loop to print spaces before the stars.
- Use the second inner loop to print stars from
1toi. - Move to the next line after printing each row.
- Stop the program.
Time Complexity
O(n²) — The program uses nested loops to print spaces and stars for each row.
Space Complexity
O(1) — The program uses only a fixed number of variables and does not require additional memory proportional to the input size.
Search Description
Learn how to write a C++ program to print a right-aligned star triangle pattern using nested loops. This beginner-friendly pattern program explains how spaces and stars are used to create a triangular shape.
Keywords
C++ star pattern program, right aligned star triangle, star triangle pattern in C++, C++ pattern programs, nested loops in C++, pyramid star pattern, right triangle pattern, star pattern using loops
Hashtags
#Cpp #CPlusPlus #CppProgramming #PatternPrograms #StarPattern #TrianglePattern #NestedLoops #ProgrammingForBeginners #Coding #DSA #1printf
C++ Program to Print Repeated Character Triangle Pattern
Source Code
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter the number:"<<endl;
cin>>num;
for(int i=1;i<=num;i++)
{
for(int k=num;k>=i;k--)
{
cout<<" ";
}
for(int j=1;j<=i;j++)
{
cout<<char(i+64)<<" ";
}
cout<<endl;
}
}
Expected Output
Enter the number:
5
A
B B
C C C
D D D D
E E E E E
Explanation
This C++ program prints a repeated character triangle pattern using nested loops. The outer loop controls the rows, while the first inner loop prints spaces to create the right-aligned triangle shape.
The second inner loop prints the same character repeatedly in each row. The expression char(i + 64) converts the row number into its corresponding uppercase alphabet character. For example, 1 + 64 = 65, which represents A in ASCII, while 2 + 64 = 66, which represents B.
Algorithm
- Start the program.
- Read the number of rows from the user.
- Run an outer loop from
i = 1tonum. - Use a loop to print spaces before the characters.
- Use another loop from
j = 1toi. - Convert
i + 64into an uppercase character usingchar(). - Print the same character repeatedly in the current row.
- Move to the next line after printing each row.
- Stop the program.
Time Complexity
O(n²) — The nested loops perform approximately n² operations to generate the pattern.
Space Complexity
O(1) — The program uses only a fixed number of variables and does not require additional memory based on the input size.
Search Description
Learn how to write a C++ program to print a repeated character triangle pattern using nested loops and ASCII values. This beginner-friendly example explains how to print the same uppercase alphabet character repeatedly in each row.
Keywords
C++ repeated character pattern, repeated alphabet triangle pattern, character triangle pattern in C++, C++ alphabet pattern, ASCII character pattern, uppercase character pattern, nested loops in C++, C++ pattern programs
Hashtags
#Cpp #CPlusPlus #CppProgramming #PatternPrograms #CharacterPattern #AlphabetPattern #ASCIIPattern #NestedLoops #ProgrammingForBeginners #Coding #DSA #1printf
C++ Program to Print Character Triangle Pattern
Source Code
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter the number:"<<endl;
cin>>num;
for(int i=1;i<=num;i++)
{
for(int k=num;k>=i;k--)
{
cout<<" ";
}
for(int j=1;j<=i;j++)
{
cout<<char(j+64)<<" ";
}
cout<<endl;
}
}
Expected Output
Enter the number:
5
A
A B
A B C
A B C D
A B C D E
Explanation
This C++ program prints an uppercase character triangle pattern using nested loops. The outer loop controls the number of rows, while the first inner loop prints spaces to create the right-aligned triangle shape.
The second inner loop prints characters using char(j + 64). In ASCII, the value 65 represents A, 66 represents B, 67 represents C, and so on. Since j starts from 1, adding 64 converts it into the corresponding uppercase alphabet character.
Algorithm
- Start the program.
- Read the number of rows from the user.
- Run an outer loop from
i = 1tonum. - Use a loop to print spaces before the characters.
- Use another loop from
j = 1toi. - Convert
j + 64into an uppercase character usingchar(). - Print the character followed by a space.
- Move to the next line after each row.
- Stop the program.
Time Complexity
O(n²) — The nested loops perform a total of approximately n² operations to generate the pattern.
Space Complexity
O(1) — The program uses only a fixed number of variables and does not require additional memory based on the input size.
Search Description
Learn how to write a C++ program to print a character triangle pattern using nested loops and ASCII values. This beginner-friendly example explains how to convert numeric values into uppercase alphabet characters using char(j + 64).
Keywords
C++ character pattern program, character triangle pattern in C++, alphabet triangle pattern, C++ alphabet pattern, ASCII value pattern, nested loops in C++, uppercase character pattern, C++ pattern programs
Hashtags
#Cpp #CPlusPlus #CppProgramming #PatternPrograms #CharacterPattern #AlphabetPattern #ASCIIPattern #NestedLoops #ProgrammingForBeginners #Coding #DSA #1printf
C++ Program to Print Repeated Binary Number Triangle Pattern
Source Code
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter the number:"<<endl;
cin>>num;
for(int i=1;i<=num;i++)
{
for(int k=num;k>=i;k--)
{
cout<<" ";
}
for(int j=1;j<=i;j++)
{
cout<<i%2<<" ";
}
cout<<endl;
}
}
Expected Output
Enter the number:
5
1
0 0
1 1 1
0 0 0 0
1 1 1 1 1
Explanation
This C++ program prints a repeated binary number triangle pattern. The program first reads the number of rows from the user. The outer loop controls the rows, while the first inner loop adds spaces to create the right-aligned triangle shape.
The second inner loop prints the value of i % 2. When i is odd, i % 2 produces 1. When i is even, it produces 0. Therefore, every row contains the same binary value.
Algorithm
- Start the program.
- Read the number of rows from the user.
- Run an outer loop from
i = 1tonum. - Use a loop to print spaces before the numbers.
- Use another loop to print
i % 2repeatedly in each row. - Move to the next line after printing each row.
- Stop the program.
Time Complexity
O(n²) — The program uses nested loops to print the spaces and binary values for each row.
Space Complexity
O(1) — The program uses only a few integer variables and does not require additional memory proportional to the input size.
Search Description
Learn how to write a C++ program to print a repeated binary number triangle pattern using nested loops and the modulus operator. This beginner-friendly example explains how to generate 1 and 0 patterns based on row numbers.
Keywords
C++ binary pattern program, repeated binary triangle pattern, binary number triangle in C++, C++ pattern programs, nested loops in C++, i%2 pattern, 1 0 pattern in C++, number pattern programs
Hashtags
#Cpp #CPlusPlus #CppProgramming #PatternPrograms #BinaryPattern #NumberPattern #NestedLoops #ProgrammingForBeginners #Coding #DSA #1printf
⭐ C++ Program to Print Binary Triangle Pattern
#include<iostream>
using namespace std;
int main()
{
int num;
cout << "Enter the number:" << endl;
cin >> num;
for(int i=1; i<=num; i++)
{
for(int k=num; k>=i; k--)
{
cout << " ";
}
for(int j=1; j<=i; j++)
{
cout << j % 2 << " ";
}
cout << endl;
}
return 0;
}
Enter the number:
5
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
π Explanation
This C++ program prints a binary triangle pattern using nested for loops. The outer loop controls the number of rows, starting from 1 and increasing up to the entered number. The first inner loop prints leading spaces to properly align the pattern, while the second inner loop prints alternating 1 and 0 values using the expression j % 2. Since the remainder alternates between 1 and 0 for consecutive values of j, the program creates a binary triangle pattern.
π§ Algorithm
- Read the number from the user.
- Start the outer loop from 1 up to the entered number.
- Print leading spaces for proper alignment.
- Print alternating 1 and 0 values using j % 2.
- Move to the next line after each row.
- Repeat until the complete binary triangle is displayed.
⏱ Time Complexity
O(n²)
πΎ Space Complexity
O(1)
π Search Description
Learn how to print a binary triangle pattern in C++ using nested loops. This beginner-friendly C++ program uses the modulo operator to generate alternating 1 and 0 values, making it useful for learning binary patterns, nested loops, and pattern printing in C++.
π Keywords
binary triangle pattern in C++, C++ program for binary pattern, 0 1 pattern in C++, binary pattern using nested loops, j % 2 pattern in C++, triangle pattern in C++, C++ pattern program, pattern printing in C++, nested loops in C++, C++ programming examples.
π· Hashtags
#CppProgramming #PatternPrograms #BinaryPattern #NumberPattern #TrianglePattern #Coding #Programming #NestedLoops #Cpp #1printf
⭐ C++ Program to Print Repeated Number Triangle Pattern
#include<iostream>
using namespace std;
int main()
{
int num;
cout << "Enter the number:" << endl;
cin >> num;
for(int i=1; i<=num; i++)
{
for(int k=num; k>=i; k--)
{
cout << " ";
}
for(int j=1; j<=i; j++)
{
cout << i << " ";
}
cout << endl;
}
return 0;
}
Enter the number:
5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
π Explanation
This C++ program prints a repeated number triangle pattern using nested for loops. The outer loop controls the number of rows, starting from 1 and increasing up to the entered number. The first inner loop prints leading spaces to properly align the pattern, while the second inner loop prints the current row number repeatedly. As the row number and the number of elements increase in each row, a repeated number triangle pattern is formed.
π§ Algorithm
- Read the number from the user.
- Start the outer loop from 1 up to the entered number.
- Print leading spaces for proper alignment.
- Print the current row number repeatedly.
- Move to the next line after each row.
- Repeat until the complete repeated number triangle is displayed.
⏱ Time Complexity
O(n²)
πΎ Space Complexity
O(1)
π Search Description
Learn how to print a repeated number triangle pattern in C++ using nested loops. This beginner-friendly C++ program prints the current row number repeatedly while increasing the number of elements in each row, making it useful for learning loops and pattern printing in C++.
π Keywords
repeated number triangle pattern in C++, C++ program for repeated number pattern, number pattern using nested loops, repeated number pattern in C++, triangle pattern in C++, C++ pattern program, pattern printing in C++, nested loops in C++, C++ programming examples.
π· Hashtags
#CppProgramming #PatternPrograms #NumberPattern #RepeatedNumberPattern #TrianglePattern #Coding #Programming #NestedLoops #Cpp #1printf
⭐ C++ Program to Print Number Triangle Pattern
#include<iostream>
using namespace std;
int main()
{
int num;
cout << "Enter the number:" << endl;
cin >> num;
for(int i=1; i<=num; i++)
{
for(int k=num; k>=i; k--)
{
cout << " ";
}
for(int j=1; j<=i; j++)
{
cout << j << " ";
}
cout << endl;
}
return 0;
}
Enter the number:
5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
π Explanation
This C++ program prints a number triangle pattern using nested for loops. The outer loop controls the number of rows, starting from 1 and increasing up to the entered number. The first inner loop prints spaces to properly align the pattern, while the second inner loop prints numbers from 1 up to the current row number. As the number of elements increases in every row, a number triangle pattern is formed.
π§ Algorithm
- Read the number from the user.
- Start the outer loop from 1 up to the entered number.
- Print leading spaces for proper alignment.
- Print numbers from 1 to the current row value.
- Move to the next line after each row.
- Repeat until the complete number triangle is displayed.
⏱ Time Complexity
O(n²)
πΎ Space Complexity
O(1)
π Search Description
Learn how to print a number triangle pattern in C++ using nested loops. This beginner-friendly C++ program prints numbers from 1 to the current row value with proper spacing and alignment, making it useful for learning loops and pattern programs in C++.
π Keywords
number triangle pattern in C++, C++ program for number pattern, number pattern using nested loops, triangle pattern in C++, C++ pattern program, pattern printing in C++, nested loops in C++, C++ programming examples.
π· Hashtags
#CppProgramming #PatternPrograms #NumberPattern #TrianglePattern #Coding #Programming #NestedLoops #Cpp #1printf
C++ Program to Print Right-Aligned Incremental Number Triangle Pattern
Source Code
#include<iostream>
using namespace std;
int main()
{
int num,a=0;
cout<<"Enter the number:"<<endl;
cin>>num;
for(int i=1;i<=num;i++)
{
for(int k=num;k>=i;k--)
{
cout<<" ";
}
for(int j=1;j<=i;j++)
{
cout<<a++<<" ";
}
cout<<endl;
}
}
Expected Output
Enter the number:
5
0
1 2
3 4 5
6 7 8 9
10 11 12 13 14
Explanation
This C++ program prints a right-aligned incremental number triangle pattern using nested loops. The outer loop controls the rows, while the first inner loop prints spaces to create the right-aligned triangle shape.
The variable a is initialized to 0. Inside the second inner loop, a++ prints the current value of a and then increments it by 1. Therefore, the numbers continue sequentially across all rows instead of restarting from 0 in each row.
Algorithm
- Start the program.
- Initialize the variable
ato0. - Read the number of rows from the user.
- Run an outer loop from
i = 1tonum. - Use the first inner loop to print spaces before the numbers.
- Use the second inner loop to print the value of
a. - Increment
aafter every number usinga++. - Move to the next line after printing each row.
- Stop the program.
Time Complexity
O(n²) — The nested loops perform approximately n² operations to generate the spaces and numbers.
Space Complexity
O(1) — The program uses only a fixed number of variables and does not require additional memory proportional to the input size.
Search Description
Learn how to write a C++ program to print a right-aligned incremental number triangle pattern using nested loops. This beginner-friendly example demonstrates how to use a counter variable with the post-increment operator to print continuous numbers across multiple rows.
Keywords
C++ number pattern program, incremental number triangle, continuous number pattern in C++, right aligned number triangle, C++ pattern programs, nested loops in C++, number triangle using loops, sequential number pattern
Hashtags
#Cpp #CPlusPlus #CppProgramming #PatternPrograms #NumberPattern #NumberTriangle #NestedLoops #ProgrammingForBeginners #Coding #DSA #1printf
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment