X的金字塔。 ?! (请有一个E E E) [英] Pyramid Of X's. ?! (Please Have An E Y E)

查看:57
本文介绍了X的金字塔。 ?! (请有一个E E E)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在构建逻辑方面遇到了问题..

请帮助明天是我的论文,我必须完成这个ASA P.

还有更多问题要解决考试前完成...



我想绘制X'的金字塔..

例如用户输入9作为输入输出应该是:



I am facing problem in building logic ..
Please Help Tomorrow Is My Paper, I''ve to complete this A S A P.
There are more problems to be completed before the exam ...

I want to draw pyramid of X''s..
for instance user enter 9 as an input the output should be:

<br />
. . . . X<br />
. . . X X X<br />
. . X X X X X<br />
. X X X X X X X<br />
X X X X X X X X X<br />





这是我的代码但它跳过了最后一行它应该打印9 X'..:/ ?? :/





Here Is My Code But It Skips The Last Line Where It Should Print 9 X''s .. :/ ?? :/

void main ()
 {
	 int length;
	 cout << " STARS?: ";
	 cin >> length;
	 int temp = length/2;
	 for (int i = 0; i < temp; i++)
	 {
		 for (int j = temp - i; j > 0; j--)
		 {
			 cout << ". ";
		 }
		 for (int k = 0; k < 2*i+1; k++)
		 {
			 cout << "* ";
		 }
		 cout << '\n';
	 }
 }





我不想要完整的代码..

您的建议将不胜感激。!!!

推荐答案

1。在你的外部循环中,你增加 i 而不是

2. space stars 未申报且未初始化。

3.内部虽然循环从不运行,或永不停止(一旦输入,就无法改变循环条件)。



修复这些问题,以便代码编译并运行并执行某些操作,然后逐步执行以验证您的逻辑。
1. In your outer loop, you increment i instead of row.
2. space and stars are undeclared and uninitialised.
3. The inner while loop is either never run, or never stops (once entered, there''s no way to change the loop condition).

Fix those problems, so your code compiles and runs and does something, then step through it to verify your logic.


根据您更新的代码(v4),更改以下内容:



1.外部用于循环头行更改 i ++ ++行

2.内圈换头线 col<长度 col<行

3.删除while循环(我甚至不确定你需要它)

4.而不是 cout<< 。; cout<< *; (你确实想要星号,没有?;))

5.移动行cout<<'' \\ n'';在内部for循环之外和之后



你没有指明金字塔的形式,但是如果你有这样的变化,你应该这样:



Based on your updated code (v4), change the following:

1. outer for loop head line change i++ to ++row
2. inner for loop head line change col < length to col < row
3. remove the while loop (I'' m not even sure what you needed it for)
4. instead of cout << ". "; write cout << "* "; (you did want asterisks, no? ;))
5. Move the line "cout << ''\n'';" outside and behind the inner for loop

you didn''t specify what form that pyramid shoud be, but with the changes above you should get sth like that:

*<br />
* *<br />
* * *<br />
* * * *<br />





请注意第2步和第3步显着改变了你的程序逻辑,我不知道结果是否符合你的意图。但是当你有效地处理二维矩阵中的字符时,你并没有说明空间有什么用处,或者为什么你认为你需要第三个嵌套循环。我没看到你从哪里得到第三个维度。



Note that steps 2 and 3 change your program logic significantly, and I don''t know if the results match your intention. But then you didn''t state what the spaces are good for, or why you think you need a third nested loop when you are effectively addressing characters in a two-dimensional matrix. I don''t see where you get that third dimension from.


这篇关于X的金字塔。 ?! (请有一个E E E)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆