-->





upside down filled isosceles triangle code C++

Write a program which display upside down isosceles triangle using nested for loop and asterisk character
Output should be look like below image

upside down filled isosceles triangle code C++ sample image



C++ code:





#include<iostream>
using namespace std;

int main()
{
  int e=9;

  cout<<"\"Upside Down Triangle\":\n\n";

  for(int a=1;a<=5;a++)
 {
    for(int b=0;b<e;b++)
   {
    cout<<"*";  // printing asterisk character
   }
    cout<<endl;
    e=e-2;

      for(int c=0;c<a;c++)
     {
      cout<<" ";  // printing space here
     }

 }
 return 0;
}


Sample Output:
upside down filled isosceles triangle code C++ sample output
sample output

More C++ Shapes Here


8 comments:

  1. Replies
    1. Yes Zainab It can be generic too. Set Variables in For Loops Then Take Input in Variables.
      Like Replace 5 by Variable.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. You can also use the code for:
    *****
    ****
    ***
    **
    *
    to built an upside down triangle by just putting one space before or after asterisk (i.e cout<<" *" or cout<< "* ") in 3rd for loop.

    ReplyDelete
  4. ----------------
    ----- *---------
    ---*****------
    ----***--------
    ---*-----*-------


    how to do this using C++?

    ReplyDelete
  5. how to print a diamond using a c++ code ? please help!

    ReplyDelete
  6. why do you used a<=5 only in the first for loop..please tell fast

    ReplyDelete
  7. My output is
    *******
    *****
    ***
    *
    Why?

    ReplyDelete