C++ Program to Print Right Triangle Star Pattern

In this article, we are going to write a C++ program in which we are going to print right-angle triangles using ‘*’.

C++ Program to Print Right Triangle Star Pattern


*
**
***
****
if you observe the pattern properly you will find that the pattern is in right angle shape, apart from this you will also find that the column is increasing with the row right! We can also say that if each element is increasing in the row when a row is increasing the element is increasing. All right now we think that you are more clear with the pattern. before moving toward the C program let’s see the input and output of the program. Then we will move toward the code.

Example

Input- Enter the range of the number of rows:5

Output : *

*  *

*  *  *

*  *  *  *

*  *  *  *  *

Now, what is the logic behind this-

The logic behind this program is simple, we have to run for loop twice upper for loop to print horizontal rows, and the inner loop to print the vertical column of the right angle triangle.

Then we have to print our output of the program, and in the end, we applied a new line character ‘n’.For more understanding, you can see the program and program explanation.

Program-

#include<iostream>
using namespace std;
int main()
{
int i,j,rows;
cout<<“Enter the range of number of rows :”;
cin>>rows;
cout<<endl;
for(i=0;i<rows;i++)
{
for(j=0;j<=i;j++){

cout<<” * “;
}
cout<<“n”;
}
return 0;
}

Output-

Enter the range of the number of rows :3

*

*  *

*  *  *

Program Explanation-

  • First of all, we have declared variables to values of rows and i, j for iteration of loops.
  • Then we have taken a number of rows as user input for how much bigger or smaller the user wants the pattern.
  • Then we applied the end line to print the pattern one line below the input.
  • Then we applied the upper for loop to print horizontal rows of right-angle triangles.
  • Then we applied the inner for loop to print vertical lines of the right angle triangle.
  • Then in the inner loop, we have printed ‘*’ from which our pattern has been made.
  • At the end of the outer loop, we have printed the ‘n’ newline character.

Conclusion

In this article, we have seen the C++ program which has to print the start pattern. We hope that you have understood the pattern program, Once you understood the program you will find it easy and simple hope that you will explore it more!