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 4: Star, Number, Alphabet & Binary Patterns with Output
⭐ C++ Program to Print Decreasing Star Triangle Pattern
This C++ program prints a decreasing star triangle pattern using nested for loops. The number of stars decreases by one in every row.
π Source Code
#include<iostream>
using namespace std;
int main()
{
int num,k=0;
cout<<"Enter the number:"<<endl;
cin>>num;
for(int i=num;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
cout<<"* ";
}
cout<<endl;
}
}
π» Expected Output
Enter the number: 5 * * * * * * * * * * * * * * *
π Explanation
The program first takes a number from the user and stores it in the variable num. The outer loop starts from num and decreases the value of i until it reaches 1.
The inner loop runs from 1 to i. During each iteration, it prints *. Therefore, the first row contains num stars, and every following row contains one fewer star.
For example, when num = 5, the number of stars printed in each row is: 5, 4, 3, 2, 1.
π§ Algorithm
1. Start the program.
2. Declare the variable num.
3. Read the value of num from the user.
4. Initialize the outer loop from num down to 1.
5. For each value of i, run the inner loop from 1 to i.
6. Print * in every iteration of the inner loop.
7. Move to the next line after completing each row.
8. Repeat until the outer loop reaches 1.
9. Stop the program.
⏱ Time Complexity
n + (n-1) + (n-2) + ... + 1 = n(n+1)/2 Time Complexity = O(n²)
πΎ Space Complexity
The program uses only a few integer variables and does not require any additional data structure.
Space Complexity = O(1)
π Search Description
C++ program to print a decreasing star triangle pattern using nested for loops. Learn how to print stars in decreasing order with a simple C++ pattern program suitable for beginners.
π Keywords
C++ star pattern, C++ star triangle, decreasing star pattern, decreasing triangle pattern, inverted star triangle, C++ pattern programs, star pattern program in C++, C++ nested loops, C++ for loop pattern, triangle pattern in C++, star printing program, beginner C++ programs, pattern printing in C++
π· Hashtags
#CppProgramming #Cpp #PatternPrograms #StarPattern #StarTriangle #DecreasingPattern #TrianglePattern #InvertedTriangle #NestedLoops #ForLoop #Coding #Programming #LearnCpp #CppPatterns #1printf
⭐ C++ Program to Print Decreasing Consecutive Number Triangle Pattern
This C++ program prints a decreasing triangle pattern using consecutive numbers starting from 0. The number of elements decreases in every row, while the value of k continues increasing throughout the pattern.
π Source Code
#include<iostream>
using namespace std;
int main()
{
int num,k=0;
cout<<"Enter the number:"<<endl;
cin>>num;
for(int i=num;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
cout<<k++<<" ";
}
cout<<endl;
}
}
π» Expected Output
Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
π Explanation
The program first takes a number from the user and stores it in the variable num. The variable k is initialized to 0.
The outer loop starts from num and decreases i until it reaches 1. This controls the number of elements printed in each row.
The inner loop runs from 1 to i. During every iteration, the expression k++ prints the current value of k and then increases it by 1.
Because k is declared outside both loops, its value is not reset when a new row starts. Therefore, the numbers continue sequentially from one row to the next.
π§ Algorithm
1. Start the program.
2. Declare num and initialize k = 0.
3. Read the value of num from the user.
4. Initialize the outer loop from num down to 1.
5. For each row, run the inner loop from 1 to i.
6. Print the current value of k and increment it using k++.
7. Move to the next line after completing each row.
8. Repeat until the outer loop reaches 1.
9. Stop the program.
⏱ Time Complexity
n + (n-1) + (n-2) + ... + 1 = n(n+1)/2 Time Complexity = O(n²)
πΎ Space Complexity
The program uses only a few integer variables and does not require any additional data structure.
Space Complexity = O(1)
π Search Description
C++ program to print a decreasing consecutive number triangle pattern starting from 0. Learn how to use nested for loops and a counter variable to print continuous numbers across multiple rows.
π Keywords
C++ number pattern, C++ pattern programs, consecutive number triangle, decreasing number triangle, continuous number pattern, consecutive number pattern in C++, number triangle pattern, C++ nested loops, C++ for loop pattern, counter variable in C++, C++ pattern printing, beginner C++ programs, triangle pattern program
π· Hashtags
#CppProgramming #Cpp #PatternPrograms #NumberPattern #ConsecutiveNumbers #NumberTriangle #DecreasingPattern #TrianglePattern #NestedLoops #ForLoop #Coding #Programming #LearnCpp #CppPatterns #1printf
⭐ C++ Program to Print 0 1 Decreasing Triangle Pattern
This C++ program prints a decreasing triangle pattern using 0 and 1. Each row contains the same value, and the value changes between 0 and 1 for every row. The pattern is generated using nested for loops and the modulus operator %.
π Source Code
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter the number:"<<endl;
cin>>num;
for(int i=num;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
cout<<i%2<<" ";
}
cout<<endl;
}
}
π» Expected Output
Enter the number: 5 1 1 1 1 1 0 0 0 0 1 1 1 0 0 1
π Explanation
The program first takes a number from the user and stores it in the variable num. The outer loop starts from num and decreases the value of i until it reaches 1.
The inner loop runs from 1 to i. In every iteration, the expression i % 2 is calculated and printed. Since the value of i remains the same throughout a row, the same 0 or 1 is printed for that entire row.
If i is odd, i % 2 gives 1. If i is even, i % 2 gives 0. Therefore, the rows alternate between 1 and 0.
π§ Algorithm
1. Start the program.
2. Read the number from the user.
3. Initialize the outer loop from num down to 1.
4. For each value of i, calculate i % 2.
5. Run the inner loop from 1 to i.
6. Print i % 2 in every iteration of the inner loop.
7. Move to the next line after completing each row.
8. Stop the program.
⏱ Time Complexity
n + (n-1) + (n-2) + ... + 1 = n(n+1)/2 Time Complexity = O(n²)
πΎ Space Complexity
The program uses only integer variables and does not require any additional data structure.
Space Complexity = O(1)
π Search Description
C++ program to print a 0 1 decreasing triangle pattern using nested for loops and the modulus operator. Each row contains repeated 0 or 1 values, creating an alternating binary number pattern.
π Keywords
C++ 0 1 pattern, C++ binary pattern, 0 1 triangle pattern, decreasing 0 1 pattern, repeated 0 1 pattern, binary triangle pattern in C++, C++ pattern programs, C++ nested loops, C++ modulus operator, C++ for loop pattern, number pattern in C++, beginner C++ programs, pattern printing in C++
π· Hashtags
#CppProgramming #Cpp #PatternPrograms #01Pattern #BinaryPattern #NumberPattern #TrianglePattern #DecreasingPattern #NestedLoops #ForLoop #ModulusOperator #Coding #Programming #LearnCpp #CppPatterns #1printf
⭐ C++ Program to Print 0 1 Decreasing Triangle Pattern
This C++ program prints a decreasing triangle pattern containing alternating 0 and 1 values using nested for loops and the modulus operator %.
π Source Code
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter the number:"<<endl;
cin>>num;
for(int i=num;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
cout<<j%2<<" ";
}
cout<<endl;
}
}
π» Expected Output
Enter the number: 5 1 0 1 0 1 1 0 1 0 1 0 1 1 0 1
π Explanation
The program first takes a number from the user and stores it in the variable num. The outer loop starts from num and decreases the value of i until it reaches 1.
The inner loop starts from 1 and runs up to i. In every iteration, the expression j % 2 is calculated.
When j is odd, j % 2 gives 1. When j is even, j % 2 gives 0. Therefore, the output alternates between 1 and 0.
π§ Algorithm
1. Start the program.
2. Read the number from the user.
3. Initialize the outer loop from num down to 1.
4. For each value of i, run the inner loop from 1 to i.
5. Calculate j % 2 and print the result.
6. Move to the next line after completing each row.
7. Stop the program.
⏱ Time Complexity
n + (n-1) + (n-2) + ... + 1 = n(n+1)/2 Time Complexity = O(n²)
πΎ Space Complexity
The program uses only a few integer variables and does not use any additional data structure.
Space Complexity = O(1)
π Search Description
C++ program to print a decreasing 0 1 number triangle pattern using nested for loops and the modulus operator. Learn how to create alternating 0 and 1 patterns in C++ with simple programming logic.
π Keywords
C++ 0 1 pattern, C++ 0 1 triangle, C++ binary pattern, 0 1 number pattern, decreasing 0 1 pattern, 0 1 triangle pattern in C++, C++ pattern programs, C++ nested loops, C++ modulus operator, C++ for loop pattern, binary number pattern, beginner C++ programs, pattern printing in C++
π· Hashtags
#CppProgramming #Cpp #PatternPrograms #NumberPattern #01Pattern #BinaryPattern #TrianglePattern #DecreasingPattern #NestedLoops #ForLoop #ModulusOperator #Coding #Programming #LearnCpp #1printf
⭐ C++ Program to Print Decreasing Repeated Number Triangle Pattern
This C++ program prints a decreasing number triangle pattern using nested for loops. Each row contains the same number, and the number of elements decreases by one in every row.
π Source Code
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter the number:"<<endl;
cin>>num;
for(int i=num;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
cout<<i<<" ";
}
cout<<endl;
}
}
π» Expected Output
Enter the number: 5 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
π Explanation
The program first takes a number from the user and stores it in the variable num. The outer loop starts from num and decreases the value of i until it reaches 1.
The inner loop runs from 1 to i. During every iteration, the value of i is printed. Therefore, every row contains the same number, while the number of elements decreases in each row.
π§ Algorithm
1. Start the program.
2. Read the number from the user.
3. Initialize the outer loop from num down to 1.
4. For each value of i, run the inner loop from 1 to i.
5. Print the value of i in each iteration of the inner loop.
6. Move to the next line after completing each row.
7. Stop the program.
⏱ Time Complexity
The outer loop runs n times and the inner loop runs a decreasing number of times. Therefore, the total number of operations is approximately:
n + (n-1) + (n-2) + ... + 1 = n(n+1)/2 Time Complexity = O(n²)
πΎ Space Complexity
The program uses only a few integer variables and does not require additional data structures.
Space Complexity = O(1)
π Search Description
C++ program to print a decreasing repeated number triangle pattern using nested for loops. Learn how to create number patterns in C++ with simple loops and beginner-friendly programming logic.
π Keywords
C++ number pattern, C++ pattern programs, decreasing number pattern, repeated number triangle, decreasing repeated number triangle, number triangle pattern in C++, C++ nested loops, C++ for loop pattern, triangle pattern program, beginner C++ programs, C++ pattern printing, number pattern programs
π· Hashtags
#CppProgramming #Cpp #PatternPrograms #NumberPattern #NumberTriangle #DecreasingPattern #TrianglePattern #NestedLoops #ForLoop #Coding #Programming #LearnCpp #CppPatterns #1printf
⭐ C++ Program to Print Decreasing Number Triangle Pattern
#include<iostream>
using namespace std;
int main()
{
int num;
cout << "Enter the number:" << endl;
cin >> num;
for(int i=num; i>=1; i--)
{
for(int j=1; j<=i; j++)
{
cout << j << " ";
}
cout << endl;
}
return 0;
}
Enter the number:
5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
π Explanation
This C++ program prints a decreasing number triangle pattern using nested for loops. The outer loop starts from the entered number and decreases down to 1. Therefore, the number of elements in each row decreases by one.
The inner loop starts from 1 and runs up to the current value of i. It prints the numbers from 1 to i in each row. After completing each row, cout << endl moves the cursor to the next line.
π§ Algorithm
- Start the program.
- Read the number from the user.
- Start the outer loop from
i = numand decrease it down to1. - Start the inner loop from
j = 1up toi. - Print the value of
jfollowed by a space. - Move to the next line after printing each row.
- Repeat until
ibecomes 1. - Stop the program.
⏱ Time Complexity
O(n²) — The nested loops perform approximately n² operations to generate the complete number pattern.
πΎ 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 print a decreasing number triangle pattern in C++ using nested loops. This beginner-friendly C++ program prints numbers from 1 to the current row value while decreasing the number of elements in each row.
π Keywords
decreasing number triangle pattern in C++, C++ program for decreasing number pattern, inverted number triangle in C++, number pattern using nested loops, reverse number triangle in C++, C++ pattern program, pattern printing in C++, nested loops in C++, C++ programming examples, number triangle pattern.
π· Hashtags
#CppProgramming #PatternPrograms #NumberPattern #DecreasingPattern #NumberTriangle #TrianglePattern #Coding #Programming #NestedLoops #Cpp #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