C++ 具有3个环的平行四边形,带c++;
这是我计算机科学的第一年,我在这个问题上遇到了一些麻烦。 讲师要求为平行四边形编写代码: 输入行数:13C++ 具有3个环的平行四边形,带c++;,c++,C++,这是我计算机科学的第一年,我在这个问题上遇到了一些麻烦。 讲师要求为平行四边形编写代码: 输入行数:13 * ** *** **** ***** ****** ******* ****** ***** **** *** ** * …强制奇数输入(如4变为5)。规则是-我不能使用stew-必须仅使用3个循环绘制形状-加上一个强制输入循环(r在3到23之间)-必须使用总行数或当前行数进行所有计算(不能使用前一行,也不能生成自己的数字) intmain(){
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
…强制奇数输入(如4变为5)。规则是-我不能使用stew-必须仅使用3个循环绘制形状-加上一个强制输入循环(r在3到23之间)-必须使用总行数或当前行数进行所有计算(不能使用前一行,也不能生成自己的数字)
intmain(){
int控制=0;
int i=0,j=0,k=0,l=0;
int r=0,c=0,crntRow=0,crntRow2=0,
cuur_8r=0,空间=0,星=0;
字符a='-',b='+';
//cin>>r;
r=11;
如果(!(r%2))
r++;
c=0;
//cout您的讲师提到的三个循环是:
线上的外环
循环,用于为每行添加前缀空格(前半部分为0个空格)
在每行上打印星号的循环(始终为非零)
下面是一个非常简单的例子:
int i, j, k, sp, st;
int r = 11;
// 1. An outer loop over the lines
for (i = 0; i < r; i++)
{
if(i <= r/2) {
sp = 0; // No spaces in the first half
st = i + 1; // Increasing stars in the first half
} else {
sp = i - r / 2; // Increasing spaces in the second half
st = r - i; // Decreasing stars in the second half
}
// 2. A loop to prefix spaces to each line (0 spaces for the first half)
for(j = 0; j < sp; j++) cout << ' ';
// 3. A loop to print stars on each line (this is always non-zero)
for(k = 0; k < st; k++) cout << '*';
cout << '\n';
}
inti,j,k,sp,st;
int r=11;
//1.线路上的外环
对于(i=0;i 如果(我相信你的解决方案,你的问题也需要奇数行)?因为用偶数,你不能得到你在第一个代码片段中提到的内容吗?对,它必须是奇怪的,因为图的中心,偶数会使图在中间看起来很有趣。中间部分应该是(奇数)。r/2+1太棒了,非常感谢!!我花了太多时间试图修复错误的部分=[。我想尝试一下这个练习,但我不知道如何将字符正确地放在哪里打印出来。
int i, j, k, sp, st;
int r = 11;
// 1. An outer loop over the lines
for (i = 0; i < r; i++)
{
if(i <= r/2) {
sp = 0; // No spaces in the first half
st = i + 1; // Increasing stars in the first half
} else {
sp = i - r / 2; // Increasing spaces in the second half
st = r - i; // Decreasing stars in the second half
}
// 2. A loop to prefix spaces to each line (0 spaces for the first half)
for(j = 0; j < sp; j++) cout << ' ';
// 3. A loop to print stars on each line (this is always non-zero)
for(k = 0; k < st; k++) cout << '*';
cout << '\n';
}