Created
October 25, 2016 13:03
-
-
Save kiras0518/b3058842b3c1b6218a161e8aeddaa58b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
算全部格子總和 v.1 | |
*/ | |
var total = 0 | |
var i = 0 //行 | |
var j = 0 //列 | |
for i in 0...7 | |
{ | |
for j in 0...7 | |
{ | |
total = total + i * j | |
} | |
} | |
print ("格子內總數為:",total) | |
/* | |
算全部格子總和 v.2 | |
*/ | |
var total1 = 0 | |
var i = 0 | |
var j = 0 | |
for i in 0...7 | |
{ | |
for j in 0...7 | |
{ | |
if i % 2 == 1 //取餘數來判斷是否為奇數 | |
{ | |
total1 = total1 + i * j | |
} | |
} | |
} | |
print ("奇數格子內總數為:",total1) | |
/* | |
所有格子的總和,除了列數>=行數的格子 v.3 | |
*/ | |
var total2 = 0 | |
var i = 0 | |
var j = 0 | |
for i in 0...7 | |
{ | |
for j in 0...7 | |
{ | |
if j>i | |
{ | |
total2 = total2 + i * j //列>=行 | |
} | |
} | |
} | |
print ("格子內總和-列數>=行數的格子為:",total2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment