Day7 functionType

 

                              **Day 8

                              **Function Style

 

func add(a:Int,b:Int) -> Int

{

    return a+b

}

 

add(5, b: 6)

 

let anotherAdd:(Int,Int)-> Int = add

 

anotherAdd(1,1)

 

var a = 5,b=1

 

swap(&a, &b)

a

b

 

func changeScores1(inout scores:[Int])

{

    for i in 0..<scores.count

    {

        scores[i] = Int( Double(scores[i]) / 150.0 * 100.0 )

        

    }

}

 

var scores1 = [1,5,1,5,4,2,3]

changeScores1(&scores1)

scores1

 

 

 

func changeSorts(inout number:[Int])

{

 

    for i in 0..<number.count

    {

        number[i] = Int(number[i]*10)

    }

    

}

 

var arr = [55,6,1,88]

 

changeSorts(&arr)

 

arr

 

 

 

var a = 9

 

var b = sqrt(Double(a))

 

func binarySystem(number:Int) -> String

{

    var resultValue : String = ""

    

    var result = number

    

    while result > 0

    {

    

        resultValue = String(result%2) + resultValue

        

        result /= 2

        

        print(result)

        

    }

    

    return resultValue

    

}

 

 

binarySystem(6)

 

 

 

 

原文地址:https://www.cnblogs.com/tony0571/p/5373897.html