1.普通代码
#include <iostream>
using namespace std;
int main()
{
int n;//行数
cout << "请输入正三角形的层数: n= " ;
cin>>n;
if (n)//n:层数
{
for (int i = 1; i <= n; i++) //i:从第一层到第n层
{
for (int k = 0; k < n-i; k++) //k:kongge空格
{
cout << " ";
}
for (int j = 0; j < 2 * i - 1; j++)
{
cout << "*";
}
cout << endl;
}
}
}
2.
///////////////////////////////////////////////////
//正三角形
// *
// * * *
//* * * * *
//////////////////////////////////////////////////
#include <iostream>
using namespace std;
int CalcStarCount(int layer)
{
return (2 * layer - 1);
}
void DrawStar(int maxLayer, int layer)
{
i