-
Notifications
You must be signed in to change notification settings - Fork 16
/
PrintPatterns.swift
49 lines (36 loc) · 950 Bytes
/
PrintPatterns.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//Sayed Mahmudul Alam
//Patterns
struct PrintPatterns {
func printPatternA(n: Int) {
for i in 0..<n {
for j in 0...i {
print("* ", terminator: "")
}
print()
}
}
func printPatternB(n: Int) {
var l = 2*n - 2
for i in 0..<n {
for j in 0..<l {
print(" ", terminator: "")
}
l = l - 2
for k in 0...i {
print("* ", terminator: "")
}
print("")
}
}
func printPyramid(n: Int) {
for i in 0..<n {
for j in 0..<n - i {
print(" ", terminator: "")
}
for k in 0...i {
print("* ", terminator: "")
}
print("")
}
}
}