创建用户在C++中定义的星形对角线
Creating a diagonal line of stars that the user has defined in C++
我必须编写一些需要创建星号对角线的代码。我知道如何编写输出三角形的代码:
cout<<"What size of stars would you like to draw? ";
cin>>star;
int space;
for(int i = 1, k = 0; i <= star; I++, k = 0)
{
for(space = 1; space <= star-i; space++)
{
cout <<" ";
}
while(k != 2*i-1)
{
cout << "* ";
k++;
}
cout << endl;
我更改了该代码以从中创建半三角形,我似乎找不到如何使其仅成为对角线。这是我对半三角形的了解:
for(int i = 1, k = 0; i <= star; i++, k = 0) {
while(k != 2*i-1) {
cout << "* ";
k++;
}
cout << endl;
}
只需将对角线想象成一个充满空白空间的半三角形:-(。
for(int i = 1, k = 0; i <= star; i++, k = 0) {
while(k != 2*i-1) {
cout << " "; // print whitespace until the end of the row
k++;
}
cout << "*" << endl; // print a dot at the end
}
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- #定义c-预处理器常量..我做错了什么
- 用C++中的一个变量定义一个常量
- 部分定义/别名模板模板参数
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- #为""定义宏;静态";针对不同的上下文
- 如何确保C++函数在定义之前声明(如override关键字)
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 当类在C++中定义时,有什么方法可以"register"类吗?
- 在命名空间中定义函数还是限定函数
- 此代码是否违反一个定义规则
- 编译C++时未定义的引用
- 不同翻译单元中不可重载的非内联函数定义
- 为什么在定义函数之前先声明它
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 在类定义之后定义一个私有方法
- 使用用户定义函数的字符串反转
- 用户定义函数中的指针和输入
- vscode g++链路故障:体系结构x86_64的未定义符号
- 创建用户在C++中定义的星形对角线