这不马上要生蛋节(圣诞节)了,鬼知道外国人生个蛋为啥还那么高兴。所以这次博主给大家带来一段自己编写一个圣诞树的简单代码,希望大家喜欢哦!
#include<iostream>
using namespace std;
int main() {
while (1) {
int n;
cin >> n;
for (int t = 1; t <= n; t++)
{
for (int i = 1; i <= n - t; i++)
cout << " ";
for (int i = 1; i <= 2 * t - 1; i++)
cout << "*";
for (int i = 1; i <= n - t; i++)
cout << " ";
cout << endl;
}
for (int i = 1; i <= n - 1; i++)
cout << " ";
cout << "|";
for (int i = 1; i <= n - 1; i++)
cout << " ";
cout << endl;
for (int i = 1; i <= n - 1; i++)
cout << " ";
cout << "|";
for (int i = 1; i <= n - 1; i++)
cout << " ";
cout << endl;
cout << "Merry Christmas" << endl;
};
}
以上就是圣诞树的c++代码了希望大家多多关注博主哦!!!