Skip to content

Instantly share code, notes, and snippets.

@kiras0518
Created October 25, 2016 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiras0518/0504563ae863bae7254018e2710f1c02 to your computer and use it in GitHub Desktop.
Save kiras0518/0504563ae863bae7254018e2710f1c02 to your computer and use it in GitHub Desktop.
/*
語法作業1,改寫function
*/
func calNumber(row:Int, column:Int) -> Int //2個參數Int傳入值 回傳一個Int
{
var total = 0
for i in 0...row
{
for j in 0...column where i%2 == 1
{
total += i*j
print(total)
}
}
return total
}
calNumber(row: 7, column: 7)
/*
語法作業1,格子總和,除了列數。=行數格子
*/
func calNumber1(row:Int, column:Int) -> Int //2個參數Int傳入值 回傳一個Int
{
var total = 0
for i in 0...row
{
for j in 0...column where j < i
{
total += i*j
print(total)
}
}
return total
}
calNumber1(row: 7, column: 7)
/*
寫個函式
華氏轉成攝氏
*/
func t(F:Int) -> Int {
var c = 0
c = (F - 32) * 5/9
return c
}
t(F: 80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment