Monday 8 February 2016

Write C++ Program to draw inverted hollow triangle

Leave a Comment
Questions:

Write C++ Program to draw inverted hollow triangle

Explanation:

This problem is simple and just demonstration of nested loop.  Below mention code is compiled in Visual Studio 2015 and output snap is attached.. If any problem you feel and want explanation feel free to contact.

Code:

/**************************************************|
/*************C++ Programs And Projects************|
***************************************************/
#include<iostream>
using namespace std;
void main()
{
      
       int w = 6;
       for (int g = 0; g<9; g++)
       {
              cout << "*";    // Displaying asterisk here
       }
       cout << endl; // endl is for new line
       for (int a = 1; a <= 3; a++)
       {
              for (int b = 0; b<a; b++)
              {
                     cout << " ";    // displaying space here
              }
              cout << "*";
              for (int c = 1; c<w; c++)
              {
                     cout << " ";
              }
              cout << "*" << endl;
              w = w - 2;
       }
       for (int e = 1; e <= 1; e++)
       {
              for (int f = 4; f >= e; f--)
              {
                     cout << " ";
              }
              cout << "*";
       }
       cout << endl;

}

Output:
 Write C++ Program to draw inverted hollow triangle


Related Articles:

C++ Shapes Code

If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: