-
Notifications
You must be signed in to change notification settings - Fork 0
/
patterns.go
55 lines (44 loc) · 1.3 KB
/
patterns.go
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
50
51
52
53
54
55
package patterns
import "fmt"
type Pattrens struct{}
// Constructor to initiate the struct
func New() *Pattrens {
return &Pattrens{}
}
// Draw a rectangular pattren has equal rows and cols
// Please visit the link to find it more
// https://takeuforward.org/pattern/pattern-1-rectangular-star-pattern/
func (p Pattrens) RectangularPattren() {
// Initialize the variable
var num int
fmt.Print("Give me the number: ")
fmt.Scan(&num)
// loop through the rows of the rectangular
for i := 0; i < num; i++ {
// loop through the cols of the rectabgle
for j := 0; j < num; j++ {
fmt.Print("*")
}
// first row is complete so we need line break here
fmt.Print("\n")
}
}
// Draw a Right Angled Triangle Pattren
// Please visit the link to find it more
// https://takeuforward.org/pattern/pattern-2-right-angled-triangle-pattern/
func (p Pattrens) RightAngledTrianglePattren() {
// Initialize the variable
var num int
fmt.Print("Give me the number: ")
fmt.Scan(&num)
// loop through the rows of the rectangle
for i := 0; i < num; i++ {
// inner loop shoud equal to the value of the outer loop so if outer loop is 1 inner loop
// display runs and display that much stars
for j := 0; j <= i; j++ {
fmt.Print("*")
}
// first row is complete so we need line break here
fmt.Print("\n")
}
}