标签:
void printTriangle(int32_t layerNum)
{
if (layerNum < 1){
return;
}
auto printSpaces = [](int32_t num)
{
for (int32_t i = 0; i != num; ++i){
printf(" ");
}
};
auto printSatrs = [](int32_t num)
{
for (int32_t i = 0; i != num; ++i){
printf("*");
}
printf("\n");
};
for (int32_t currentNum = layerNum - 1, spaceWide = 0;
currentNum != -1;
++spaceWide, --currentNum){
printSpaces(spaceWide);
printSatrs(currentNum * 2 + 1);
}
}
标签:
原文地址:http://www.cnblogs.com/wuOverflow/p/4813998.html