C++ | Drawing a right angled triangle (inverse)

Introduction

This program is to draw a right angled triangle (inverse) in c++. You can also call this pyramid but it doesn’t look like real pyramid. However you can see my next posts for drawing a real pyramid. The program draw the triangle directly no need to input any thing. This program is extendable by using different symbols instead of ‘*’ in program. Go enjoy the program. Lets begin…….

Program to draw a right angled triangle (inverse).

#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int
int i,j;
//print triangle
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
cout<<"* ";
}
cout<<endl;
}
//get character
getch();
}

Output

* * * * *
* * * *
* **
* *
*

How does it work

No need to input anything. Directly prints the triangle.

Extending it

The program can be extended by using different symbols instead of ‘*’ in program. Go ahead and extend it…..

Explanation.

  1. Include ‘iostream.h’ and ‘conio.h’ files.
  2. Add void main.
  3. Start program by first clearing the screen.
  4. Declare the variables as int (name them as you want.)
  5. Add the loop for number of rows.
  6. Add loop inside the loop added before for number of columns.
  7. Print the symbol.

At the end

You learnt creating the c++ program of Drawing a inverse right angled triangle in c++. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s