checkpoint 3: fizz buzz

그루두·2024년 4월 13일
0

100 days of SwiftUI

목록 보기
9/108

100 days of swiftui: checkpoint 3
https://www.hackingwithswift.com/quick-start/beginners/checkpoint-3

problem

The problem is called fizz buzz, and has been used in job interviews, university entrance tests, and more for as long as I can remember. Your goal is to loop from 1 through 100, and for each number:

If it’s a multiple of 3, print “Fizz”
If it’s a multiple of 5, print “Buzz”
If it’s a multiple of 3 and 5, print “FizzBuzz”
Otherwise, just print the number.

solution

for i in 1...100 {
    if i.isMultiple(of: 3) && i.isMultiple(of: 5) {
        print("FizzBuzz")
    } else if i.isMultiple(of: 3) {
        print("Fizz")
    } else if i.isMultiple(of: 5) {
        print("Buzz")
    } else {
        print("\(i)")
    }
}

코드 파일
https://github.com/soaringwave/Ios-studying/blob/202c65b8d3affad1a9f90521d47da37a2087aacf/fizzbuzz.playground/Contents.swift

profile
계속 해보자

0개의 댓글

관련 채용 정보