使用嵌套循环的数字模式 [英] Number pattern using nested loop

查看:77
本文介绍了使用嵌套循环的数字模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请使用嵌套循环打印此数字模式



1

3 1

5 3 1

7 5 3

9 7 5 3 1

Please print this number pattern using nested loop

1
3 1
5 3 1
7 5 3 1
9 7 5 3 1

推荐答案

我们不做功课(甚至非常简单的家庭作业,就像你的......)。

让我们自己试试并在遇到问题时在这里发布具体问题。
We don''t do your homework (even really simple homework, like yours...).
Let''s try yourself and post here specific questions when you get stuck.


它没有在这里工作。



以下是询问者的预期:

1. 首先尝试你是什么想做!你可能会发现它并不那么难。

2.制定你所做的事情看似问题/不工作。



尝试一下,告诉你是否面临问题。

各位会员非常乐意为此提供帮助。
It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it''s not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.


首先从一个倒计时到一个。

下一行开始从3开始倒数,步数为2。

下一行开始从5开始倒数到1步两个。

下一行开始从7开始倒数到1步,两步。

下一行开始从9开始倒数到1步两个。



让我们总结一下这里发生了什么:



1.最终价值每一行总是一个

2. 3 - 1 = 2和5 - 3 = 2和7 - 5 = 2和9 -7 = 2.这告诉我们for循环的起始值每行增加2。

3.没有大于9的起始值(9)。因此,当起始值大于9时,或者只是在内部循环周围使用外部循环时,让我们停止这种混乱。一个循环以2的增量递增计数,另一个循环按递减2递减计数。你去弄清楚哪一个做了哪个。这不是太难,你只是试一试。



问候,



< dd> - Manfred
You start by counting down from one to one.
The next line you start counting down from 3 to 1 with a step of two.
The next line you start counting down from 5 to 1 with a step of two.
The next line you start counting down from 7 to 1 with a step of two.
The next line you start counting down from 9 to 1 with a step of two.

Lets summarize what''s going on here:

1. The end value of each row is always one
2. 3 - 1 = 2 and 5 - 3 = 2 and 7 - 5 = 2 and 9 -7 = 2. This tells us that the start value of the for loop gets incremented by 2 for each line.
3. There is no line whith a start value greater than nine (9). So lets just stop this mess when the start value gets bigger than nine or just use an outer loop around the inner loop. One loop counts up by increments of two and the other counts down by decrements of two. You go and figure out which one does which. It isn''t too hard, you just give it a try.

Regards,

— Manfred


这篇关于使用嵌套循环的数字模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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