samedi 22 février 2020

its working fine for 2 numbers like 10 or 50 but for 100 its not working. can any one help me in this diamond pattern in swift

let N = 50

for i in 1...N
{
    for j in 0..<(N-i) {
        print(" ", terminator: "")
    }

    for j in 1...2 * i-1 {
        print("*", terminator: "")
    }
    print("")
}

if (N > 1) {
    for j in 2...N
    {
        var i = N - j + 1
        for k in 0..<(N-i)
        {
            print(" ", terminator: "")
        }

        for k in 1...2*i-1 {
            print("*", terminator: "")
        }
        print("")
    }
}

Aucun commentaire:

Enregistrer un commentaire