帮助for,while和do-while循环 [英] Help in for, while and do-while loop

查看:104
本文介绍了帮助for,while和do-while循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的需要你的帮助。我需要一个程序,使用for,while和do-while循环... 3程序代码使用这3个循环得到下面的输出...请...我真的需要你的帮助。

输出:


1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

1 2 3 4 5 6

1 2 3 4 5 6 7

1 2 3 4 5 6 7 8

1 2 3 4 5 6 7 8 9

1 2 3 4 5 6 7 8 9 10

以及相反的


10 9 8 7 6 5 4 3 2 1

10 9 8 7 6 5 4 3 2

10 9 8 7 6 5 4 3

10 9 8 7 6 5 4

10 9 8 7 6 5

10 9 8 7 6

10 9 8 7

10 9 8

10 9

10


非常感谢非常感谢..非常感谢。

I really need your help everyone. i need a program that results the output below using for, while, and do-while loop..3 program codes using those 3 loops...please..i really need your help.

Output:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10

and also the reverse

10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2
10 9 8 7 6 5 4 3
10 9 8 7 6 5 4
10 9 8 7 6 5
10 9 8 7 6
10 9 8 7
10 9 8
10 9
10

Great help is really appreciated..thank you very much.

推荐答案

最简单的接近方式问题是试图打印

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

1 2 3 4 5 6

1 2 3 4 5 6 7

1 2 3 4 5 6 7 8

1 2 3 4 5 6 7 8 9

1 2 3 4 5 6 7 8 9 10

使用其中一个循环结构。


,例如使用while()的伪代码中的算法类似于
the simplest way to approach the problem is to attempt to print
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
using one of the loop constructs.

e.g. the algorithm in pseudo code using a while() would be something like
展开 | 选择 | Wrap | 行号


非常感谢您的快速回复先生..顺便说一下,我使用了for循环然后输出结果就是这样..


11212312345612345671234567812345678912345678910 :(


可以有人让我知道如何打破界限......?

这里是我的代码:


#include < iostream.h>

#include< conio.h>


int main(void )


{

int i,j;

for(i = 1; I< = 10; i ++)

for(j = 1; j< = i; j ++)

cout<< j;

返回0;

}
Thank you very much for that quick reply sir..by the way, i used the for loop but then then the output turns out like this..

11212312345612345671234567812345678912345678910 :(

can somebody give me an idea how to break the line...?

here''s my code:

#include <iostream.h>
#include <conio.h>

int main (void)

{
int i, j;
for(i=1; i<=10; i++)
for(j=1; j<=i; j++)
cout << j;
return 0;
}



非常感谢你们快速回复先生..顺便说一句,我用了for循环然后输出结果就是这样..


11212312345612345671234567812345678912345678910 :(


有人能告诉我如何打破这条线......?
}
Thank you very much for that quick reply sir..by the way, i used the for loop but then then the output turns out like this..

11212312345612345671234567812345678912345678910 :(

can somebody give me an idea how to break the line...?

}



你忘了在外部循环的末尾打印换行符,例如

you forgot to print the newline at the end of the outer loop, e.g.

展开 | 选择 | Wrap | 行号


这篇关于帮助for,while和do-while循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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