-->




C++ code to display filled isosceles triangle using for loop and asterisk character

5 comments
Write a program which draw isosceles Triangle Shape with asterisk(*) and using nested for loop
 Program required output:

display  isosceles triangle using for loop and asterisk character




C++ Code:


#include<iostream>
using namespace std;

int main()
{

  int e=1;

  cout<<"\" Triangle Shape SHAPE \":\n\n";

  for(int a=1;a<=5;a++)
 {
    for(int b=4;b>=a;b--)
   {
    cout<<" ";  // Printing Space Here
   }
      for(int c=0;c<e;c++)
     {
       cout<<"*";  // Printing asterisk here
     }
      cout<<endl;   // new line
      e=e+2;
 }
}



Program Output:
sample output filled isosceles triangle asterisk character




More C++ Shapes Here


These kind of programs are very helpful in the understanding of nested for loop.

5 comments:

  1. #include
    using namespace std;
    int main()
    {
    for(int i=1;i<=5;i++)
    {
    for(int j=4;j>=i;j--)
    cout<<" ";
    for(int k=1;k<=2*i-1;K++)
    cout<<"*";
    cout<<endl;
    }
    return 0;
    }

    ReplyDelete
  2. I use this code and the output is just a half triangle. Whatto do with that?

    ReplyDelete
  3. I use this code and the output is just a half triangle. Whatto do with that?

    ReplyDelete
  4. so what does it mean e=e+2; in this example above and why cstart 0 and e starts 1

    for(int c=0;c<e;c++)
    {
    cout<<"*"; // Printing asterisk here
    }
    cout<<endl; // new line
    e=e+2;

    ReplyDelete
  5. plz reply to me i have an assigment coz ididnot understood nested loop for writng the shapes plzzzz clarify to me each and every thing and each for loop and its function

    ReplyDelete