我可能会错过这里的明显但...... [英] I might be missing the obvious here but...

查看:64
本文介绍了我可能会错过这里的明显但......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这组代码

#include< iostream>

使用命名空间std;
$


int main()

{

  &NBSP; int< g class =" gr_ gr_31 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace"数据-GR-ID =" 31 QUOT; id =" 31"> len< / g> ;;
$


  &NBSP; cout<< "输入数字:";

  &NBSP; cin>> len;



  &NBSP; for(int i = 0; i< len; i ++)

  &NBSP; {

  &NBSP; for(int j = i + 1; j< len; j ++)

  &NBSP; {

  &NBSP; &NBSP; &NBSP; cout<< " " ;;

  &NBSP; }
  &NBSP; cout<< "#" << endl;

  &NBSP; }
}

#include <iostream>
using namespace std;

int main()
{
    int <g class="gr_ gr_31 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="31" id="31">len</g>;

    cout << "Enter a number: ";
    cin >> len;

    for (int i = 0; i < len; i++)
    {
    for (int j = i+1; j < len; j++)
    {
        cout << " ";
    }
    cout << "#" << endl;
    }
}

基本上,对于问题的第一部分,我必须更改内部< g class =" gr_ gr_158 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar replaceWithoutSep"数据-GR-ID =" 158" ID = QUOT; 158">作为< / g取代;循环到
循环。

Basically, for the first part of the problem, I have to change the inner <g class="gr_ gr_158 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar replaceWithoutSep" data-gr-id="158" id="158">for</g> loop to a while loop.

对于第二部分,我必须将外部for循环更改为do-while循环

For the second part, I then have to change the outer for loop to a do-while loop

有关如何执行此操作的任何建议吗?

Any suggestions on how to do this?

推荐答案



基本上,对于问题的第一部分,我必须将内部循环更改为while循环。


Basically, for the first part of the problem, I have to change the inner loop to a while loop.

对于第二部分,我必须将外部for循环更改为do-while循环

For the second part, I then have to change the outer for loop to a do-while loop

有关如何执行此操作的任何建议吗?

Any suggestions on how to do this?

我认为这显然是一个课程作业,所以我们不应该为你编码变化做太多b $ b。这是一个练习测试你的* b $ b *你对这些不同的循环结构如何运作的理解,以及b
为你提供了解决所需逻辑的第一手经验。



所以你需要考虑原始代码的作用,然后计算出使用备用循环操作所需的逻辑。 />
产生相同的结果。编程非常关注应用逻辑,并且为了能够有效地编程,你必须花费时间和b $ b努力来解决问题,直到你到达可行的方式和

逻辑解决方案。



看看你是否可以将任务分解为可以管理更多的子任务

很容易。然后将这些部件装在一起以获得最终解决方案。



- Wayne





I think this is apparently a course assignment so we shouldn't be making
too much in the way of coding changes for you. It's an exercise to test
*your* understanding of how these different loop structures operate, and
to give you first hand experience at working out the required logic.

So you need to think about what the original code is doing, then work out
the logic needed to use the alternate looping operations which will
produce the same results. Programming is very much about applied logic,
and to be able to program effectively you have to spend the time and
effort to wrestle with problems until you arrive at a workable and
logical solution.

See if you can break the task down into sub-tasks that you can manage more
easily. Then fit the parts together for the final solution.

- Wayne



这篇关于我可能会错过这里的明显但......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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