VesselWheel

UIkit 활용 구구단 예제 본문

Xcode Study

UIkit 활용 구구단 예제

JasonYang 2023. 5. 2. 12:35

import UIKit

 

/*

 

 각 단에 홀수만 곱하는 구구단을 작성하세요

 dan

 number <-- 조건 : if number % 2 == 1

 

 */

 

for dan in 2...9{

    // 1

    for number in 1...9{

        if number % 2 == 1{

            print("\(dan) X \(number) = \(dan*number)")

        }

    }

    print()

}

print("---------------------")

for dan in 2...9{

    for number in 1...9{

        if number % 2 == 0{

            print("\(dan) X \(number) = \(dan*number)")

        }

    }

    print()

}

print("---------------------")

 

/*

 짝수단만 출력하는 구구단을 작성하세요

 dan <-- if dan % 2 == 0

 number

 */

 

 

for dan in 2...9{

    if dan % 2 == 0{

        for number in 1...9{

            print("\(dan) X \(number) = \(dan*number)")

        }

    }

    print()

}

print("---------------------")

 

for dan in 2...9{

    for number in 1...9{

        if dan % 2 == 0{

            print("\(dan) X \(number) = \(dan*number)")

        }

    }

    print()

}

print("---------------------")

 

/*

 짝수단에는 짝수만 곱하고 홀수단에는 홀수만 곱하는

 구구단을 작성하세요

 */

for dan in 2...9{

    for number in 1...9{

        if dan % 2 == 0 && number % 2 == 0{

            print("\(dan) X \(number) = \(dan*number)")

        }

        if dan % 2 == 1 && number % 2 == 1{

            print("\(dan) X \(number) = \(dan*number)")

        }

    }

    print()

}

print("---------------------")

 

for dan in 2...9{

    for number in 1...9{

        if (dan % 2 == 0 && number % 2 == 0) ||

           (dan % 2 == 1 && number % 2 == 1) {

            print("\(dan) X \(number) = \(dan*number)")

        }

    }

    print()

}

print("---------------------")

 

for dan in 2...9{

    for number in 1...9{

        if dan % 2 == number % 2{

            print("\(dan) X \(number) = \(dan*number)")

        }

    }

    print()

}