-->





Translate

Hollow triangle shape in c++ programing code

2 comments
Write a program which display a hollow triangle shape using asterisk character and nested for loop

Output should be look like below image

Hollow triangle shape in c++ programing code using for loop and asterisk character




c++ code:


#include<iostream>
using namespace std;
int main()
{
   cout<<"\"Hollow Triangle Shape\"\n\n";
  int z=1;

  for (int i=0; i<7; i++)
  {
    for (int j=7; j>i; j--)
    {
      cout<<" "// displaying space here
    }
    cout<<"*";   // displaying asterisk here

    if (i!=0)
    {
      for (int k=1; k<=z; k++)
      {
        cout<<" ";
      }
      cout<<"*";
      z+=2;
    }
    cout<<endl;  // endl is for new line
  }

  for (int i=0; i<=z+1; i++)
  {
    cout<<"*";
  }

return 0;
}


Sample Output of the program
sample output Hollow triangle shape in c++ programing code


To increase or decrease the size of triangle change the value of loop variables. It is recommend to change the code and examine the output it will be more helpful.
More C++ Shapes Here

2 comments:

  1. Hi, I am struggling to print a circle with 2 to 3 loops using asteriks...please help

    ReplyDelete
  2. Very very nice.... Can do just reverse this pattern??

    ReplyDelete