首页 > 其他 > 详细

Multiples of 3 and 5

时间:2014-03-07 09:04:19      阅读:434      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 --If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
 2 --Find the sum of all the multiples of 3 or 5 below 1000.
 3 
 4 --set up iterator
 5 function list_iter()
 6     local i = 1;
 7     local n = 100;
 8     return function ()
 9         i = i + 1;
10         if i < n then
11             return i;
12         end
13     end
14 end
15 
16 local sum = 0;
17 for i in list_iter() do
18     if(i % 3 == 0 or i % 5 == 0) then
19         print(i);
20         sum = sum + i;
21     end
22 end
23 print(sum);
bubuko.com,布布扣

Multiples of 3 and 5,布布扣,bubuko.com

Multiples of 3 and 5

原文:http://www.cnblogs.com/reynold-lei/p/3585670.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!