The program of create Christmas Tree in C++ we only used for loop and if- statement.
The program can be easily understood, so the variable name in the program is given according to their task.
Here in this page we will create Christmas Tree in C++ Here heart size will be depend on user input meaning that dynamic heart will be print on screen.
Here is the program,
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int num,count=0;
int center=30; // print tree into center of screen
cout<<"Enter Number(Minimum 4 and Max 7): "; cin>>num;
cout<<"/n/n"; count=num-2;int joint=0; while(count>0) // count pyramid of tree
{
for(int row=0;row<num-count+1;row++) { for(int blank=num-joint+center;blank>=row; blank--)
{
cout<<" "; // print whole left side space
}
for(int left =0;left<=row+joint;left++)
{
cout<<"*"; // print left side part of tree
}
for(int right =0;right<=row+joint;right++)
{
cout<<"*"; // print right side part of tree
}
cout<<endl;
}
count--; // decrement in number of pyramid
joint++; // increase size of pyramid by one row
}
//print bottom of tree
int v;
for(int stem = 0;stem<2;stem++)
{
if(num==4)
v=1;
else
v=0;
cout<<setw(v+center+num+num-num/2);
cout<<"| |"<<endl;
}
return 0;
}
OUTPUT
Enter Number(Minimum 4 and Max 7): 5
**
****
******
****
******
********
**********
******
********
**********
************
**************
| |
| |
more about patterns,
- 16 Basic Pattern in C++
- 20 Complex Pattern in C++
- Christmas Tree patterns in C++
- swastik patterns in C++
C++ Examples
Like it?