C 星形图案具有高度和宽度
c++ star pattern with height and width
本文关键字:高度 更新时间:2023-10-16
我想在C 中发展以下模式。
*
***
*****
*******
*********
***********
*****
*****
*****
*****
*****
*****
*****
*****
*****
printf("Enter trunk height: ");
scanf("%d", &trunk_height);
printf("Enter trunk width: ");
scanf("%d", &trunk_width);
printf("Enter leaves width: ");
scanf("%d", &leaves_width);
毛部高度为9。
毛宽=5。
叶宽为11。
我编写一些代码,但不起作用。我的问题是如何检测毛刺的高度以及如何编写从用户获取信息的代码。
int main()
{
int i, j;
int x = 5;
int y = 1;
for(j = 1; j <= 5; j++)
{
for(i = 1; i <= x; i++)
{
cout << " ";
}
x--;
for(i = 1; i <= y; i++)
{
cout << "*";
}
y += 2;
cout << endl;
}
}
尝试以下代码:
#include<iostream>
using namespace std;
int main() {
int height = 9, width = 5, leave = 11;
// Print tree
int stars = 1;
for(int row = (leave + 2 - 1)/2; row >= 1 ; row--){
cout<<string(row, ' ')<<string(stars, '*')<<endl;
stars += 2;
}
// Print trunk
int pos = (leave - width )/2 +1;
for(int row = 0; row<height; row++){
cout<<string(pos, ' ')<<string(width, '*')<<endl;
}
}
输出:
*
***
*****
*******
*********
***********
*****
*****
*****
*****
*****
*****
*****
*****
*****
IDEONE链接
相关文章:
- C++:如何根据地形高度更新玩家身高?
- 如何更改QComboBox项目的高度大小?
- 更改高度贴图,使其在 4x4 网格上显示 16 个 hieghtmap
- 我试图用这段代码找到二叉树的高度,但它一直返回 0,有人可以告诉我为什么吗?
- C++:如何计算二叉树中其值模块高度小于 2 的节点数?
- 如何使用 C++ gdal 库将栅格地理从 EGM96 转换为 WGS84 椭球体高度基准面
- 从具有父指针和左子树和右子树高度的树中删除
- 程序输入名称和高度并显示它。我不知道如何显示列表中最高人的姓名和身高
- 我正在尝试创建一个 C++ 贪吃蛇游戏,但我似乎无法绘制第二个高度边框,我该如何解决这个问题?
- 计算树高度的函数
- 尝试创建一个程序来查找非二叉树的高度.最终得到一个很长的循环,没有答案
- 计算BST返回-1的高度混淆
- 使用递归计算一个函数中的高度和大小
- 如何从2D数组为QHeightMapSurfaceDataProxy创建高度图以显示2D傅立叶变换结果
- 接受来自键盘的树节点以确定其高度
- 在 C++ 中使用平展数组语法,崩溃取决于宽度/高度
- 在一行中初始化指针(新uint8_t[高度*宽度*3])
- 在高度模板化的库中进行代码混淆
- ID3DXFont :文本被拉伸,如何获取字体的宽度和高度?
- C ,二进制树的高度,而不是检查我的子树是否为空,而是在检查我的子树是否是叶子节点.抛出分割故障