Problem 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.

Find the sum of all the multiples of 3 or 5 below 1000.

sum=0;
arr=[];
k=1;
for i=1:999
    if mod(i,3)==0||mod(i,5)==0
        arr(k)=i;
        k=k+1;
        sum = sum + i;
    end
end


结果输出:


>> arr

arr =

  Columns 1 through 10

           3           5           6           9          10          12          15          18          20          21

  Columns 11 through 20

          24          25          27          30          33          35          36          39          40          42

  Columns 21 through 30

          45          48          50          51          54          55          57          60          63          65

  Columns 31 through 40

          66          69          70          72          75          78          80          81          84          85

  Columns 41 through 50

          87          90          93          95          96          99         100         102         105         108

  Columns 51 through 60

         110         111         114         115         117         120         123         125         126         129

  Columns 61 through 70

         130         132         135         138         140         141         144         145         147         150

  Columns 71 through 80

         153         155         156         159         160         162         165         168         170         171

  Columns 81 through 90

         174         175         177         180         183         185         186         189         190         192

  Columns 91 through 100

         195         198         200         201         204         205         207         210         213         215

  Columns 101 through 110

         216         219         220         222         225         228         230         231         234         235

  Columns 111 through 120

         237         240         243         245         246         249         250         252         255         258

  Columns 121 through 130

         260         261         264         265         267         270         273         275         276         279

  Columns 131 through 140

         280         282         285         288         290         291         294         295         297         300

  Columns 141 through 150

         303         305         306         309         310         312         315         318         320         321

  Columns 151 through 160

         324         325         327         330         333         335         336         339         340         342

  Columns 161 through 170

         345         348         350         351         354         355         357         360         363         365

  Columns 171 through 180

         366         369         370         372         375         378         380         381         384         385

  Columns 181 through 190

         387         390         393         395         396         399         400         402         405         408

  Columns 191 through 200

         410         411         414         415         417         420         423         425         426         429

  Columns 201 through 210

         430         432         435         438         440         441         444         445         447         450

  Columns 211 through 220

         453         455         456         459         460         462         465         468         470         471

  Columns 221 through 230

         474         475         477         480         483         485         486         489         490         492

  Columns 231 through 240

         495         498         500         501         504         505         507         510         513         515

  Columns 241 through 250

         516         519         520         522         525         528         530         531         534         535

  Columns 251 through 260

         537         540         543         545         546         549         550         552         555         558

  Columns 261 through 270

         560         561         564         565         567         570         573         575         576         579

  Columns 271 through 280

         580         582         585         588         590         591         594         595         597         600

  Columns 281 through 290

         603         605         606         609         610         612         615         618         620         621

  Columns 291 through 300

         624         625         627         630         633         635         636         639         640         642

  Columns 301 through 310

         645         648         650         651         654         655         657         660         663         665

  Columns 311 through 320

         666         669         670         672         675         678         680         681         684         685

  Columns 321 through 330

         687         690         693         695         696         699         700         702         705         708

  Columns 331 through 340

         710         711         714         715         717         720         723         725         726         729

  Columns 341 through 350

         730         732         735         738         740         741         744         745         747         750

  Columns 351 through 360

         753         755         756         759         760         762         765         768         770         771

  Columns 361 through 370

         774         775         777         780         783         785         786         789         790         792

  Columns 371 through 380

         795         798         800         801         804         805         807         810         813         815

  Columns 381 through 390

         816         819         820         822         825         828         830         831         834         835

  Columns 391 through 400

         837         840         843         845         846         849         850         852         855         858

  Columns 401 through 410

         860         861         864         865         867         870         873         875         876         879

  Columns 411 through 420

         880         882         885         888         890         891         894         895         897         900

  Columns 421 through 430

         903         905         906         909         910         912         915         918         920         921

  Columns 431 through 440

         924         925         927         930         933         935         936         939         940         942

  Columns 441 through 450

         945         948         950         951         954         955         957         960         963         965

  Columns 451 through 460

         966         969         970         972         975         978         980         981         984         985

  Columns 461 through 467

         987         990         993         995         996         999        1000


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值