Star patterns are interesting problems showing different shapes such as right triangles
Or use the asterisk '*' to create other triangle and rhombus shapes. These shapes are called stars In this article we will see how to display left triangle star pattern in C We take as input the number of rows of the star pattern. It will print out the corresponding patternRows.
We will develop logic to print asterisks in the table below. Let's follow the form Better understanding −* * * * * * * * * * * * * * * * * * * * *
In this example, there are 6 rows. So consider n = 6. For each row 'i' it will follow the asterisk count
Line number (i) | Star Count (j) |
---|---|
1 | 1 |
2 | 2 |
3 | 3 |
4 | 4 |
5 | 5 |
6 | 6 |
When on any row 'i', j follows i, then there are 'i' stars on that row. Let's take a look
The algorithm is: algorithm for this −#include#include using namespace std; void solve( int n ){ int i, j; for( i = 1; i <= n; i++ ) { for( j = 1; j <= i; j++ ) { cout << "* "; } cout << endl; } } int main(){ int n = 10; cout << "Left Star Pattern using " << n << " number of lines:" << endl; solve( n ); }
Left Star Pattern using 10 number of lines: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Left Star Pattern using 18 number of lines: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
When learning programming, displaying star schemas can help understand nested loops.
any language. In this article we have seen how to display a left triangle using an asterisk (stars) Enter the number of rows and it will display the number of rows There are the same number of stars in each row. We also discussed a tabulation approach to achieve Specify the number of stars for row i. Using this idea we can simply change Determine the number of stars in row i. Using this idea we can simply changeFormulas can display other types of patterns.
The above is the detailed content of C++ program to print left triangle star pattern. For more information, please follow other related articles on the PHP Chinese website!