Jan 28, 2012

Program : Equilateral Triangle empty from inside

Program : Equilateral Triangle empty from inside

Program to create a triangle like only triangle outline 
Check out Program


#include<iostream.h>
#include<conio.h>
// Create an Equilateral Triangle empty from inside
int main()
{
    int i=0,sp; // int define i and sp
  for(i=0; i<=10; i++) // first loop that work for 11 times
    {
    for(int sp=0; sp<=10-i; sp++) // loop for space like first time 5 then 4 then 3 and so on
       {
           cout << " ";
       }
      
        for(int j=0; j<1; j++) // loop to print xx that work only one time
        {
        cout <<"x";
        for(int m=0; m<=2*i; m++) // inside this one loop for give space b/w two x
{     cout<<" ";}
        cout <<"x";
        }
        cout <<endl; //next line
    }
   
    for(int s=0; s<=i; s++)  //print last line with xx
    cout << "xx";
    cout <<endl;
    getch(); //http://cplspls.blogspot.com
    return 0;
}



OUTPUT:



2 comments:

  1. C++ Program to Print Triangle of Stars

    Print triangle of stars is depend of two concept, first you need outer loop for line break and inner loop for increment and decrements.

    ReplyDelete