这个循环摆动多少? [英] how much this loop swing ?

查看:65
本文介绍了这个循环摆动多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此循环摆动多少?

对于(int i = 0; i< = 10; i = i + 2)
for(int j = 2; j< 9; ++ j,j ++)

答案是:
A)24
B)35
C)42
D)20

关键问题说A是正确的答案,但是它如何在数据结构中计算?循环如何相乘呢?请帮助我解决它……非常感谢.

how much this loop swing ??

for ( int i=0 ; i<=10 ; i=i+2)
for ( int j=2 ; j<9 ;++j,j++)

the answer is :
A) 24
B) 35
C) 42
D) 20

the key question said A is right answer but how it calculate in data structure ? how the loop multiply then? please help me to solve it ... many thanks.

推荐答案

如果您现在正在学习循环,我想您已经学习了典型的"Hello world",因此,如果您不想/不能做数学……为什么不使用以前的课程,并在简单的程序中编写代码,以在每个"swing"处打印出循环的值?

If you are now learning the loops, I guess you have already learned the typical "Hello world", so if you don''t want/can''t do the maths... why don''t you use the previous lessons and code it in an easy program to print out the values of the loop at each "swing"?

int k = 1;
for ( int i=0 ; i<=10 ; i=i+2)
{
   for (int j = 2; j < 9; ++j, j++)
   {
      Console.WriteLine("i = " + i + ", j = " + j + ", k = " + k);
      k++;
   }
}
Console.ReadLine();



这是最简单的方法,可以自己找到它,并且比在互联网上询问要快得多,即使在像CP这样受欢迎和/或人口稠密的地方也是如此.

另一个很大的优势是...如果您自己调查(应用已经掌握的知识),您将记住它们比从别人那里得到答案要容易得多.



That is the easiest way to find it out on your own and its infinitelly faster than asking in the internet, even in such a popular and/or populated place as CP

Another big advantage is... if you investigate the things on your own (applying the knowledge you already have), you will remember them easier than just getting the answer from another person.


您显然,您处于编程生涯的初期,也许您应该花更多的时间阅读笔记.

但是,您可以使用笔和纸(与您要求的另一笔相同)非常简单地解决此问题.只需写下每个表达式中变量的起始值,然后进行计算以递增每个表达式,直到测试中断循环为止.届时,您将获得每个循环重复的次数.将两者相乘即可得到答案.
You are obviously at an early stage of your programming career, maybe you should spend more time reading your notes.

However, you can work out the answer to this problem quite simply with pen and paper (same as the other one you asked). Just write down the starting values of the variables in each expression, then do the calculation to increment each one, counting until the test breaks the loop. At that point you will have the number of times each loop repeats. Multiply the two together and you get the answer.


这篇关于这个循环摆动多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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