IOS Mobile Application Development
Session 21 Swift IOS Code
------------------LOGIC BUILDING PROBLEMS-------------
// Patterns.....
for i in 1..<5
{
for j in 1...i
{
print(j,terminator:"")
}
print("")
}
for i in 1..<5
{
for j in 1...i
{
print("*",terminator:"")
}
print("")
}
for i in 0...5-1
{
print(String.init(repeating:"*",count: 5-i))
}
for i in 1...10
{
print(String.init(repeating:" ",count: 10-i)+String.init(repeating:"*",count:i))
}
for i in 1...10
{
print(String.init(repeating: " ",count: 10-i)+String.init(repeating: "*",count: 2*i - 1))
}
for i in 0...4
{
for j in stride(from: 4, to: i, by: -1)
{
print(terminator: " ")
}
for k in 0...i
{
print(k,terminator: "")
}
print("")
}
for i in stride(from: 0, to: 5, by: 1)
{
for j in stride(from: 5, to: i, by: -1)
{
print(j, terminator: "")
}
print(" ")
}
for i in stride(from: 5, to: 0, by: -1)
{
for j in stride(from: 5, to: i-1, by: -1)
{
print(j, terminator: "")
}
print(" ")
}
for i in stride(from: 5, to: 0, by: -1)
{
for j in 1...i
{
print(j, terminator: "")
}
print(" ")
}
No comments:
Post a Comment
Fell free to write your query in comment. Your Comments will be fully encouraged.