-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyramid.go
More file actions
33 lines (30 loc) · 740 Bytes
/
Pyramid.go
File metadata and controls
33 lines (30 loc) · 740 Bytes
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
package main
import (
"fmt"
)
func main(){
var resultingPyramid := printPyramid(rows)
fmt.Printf("Pyramid : %v\n",rows)
}
func printPyramid(rows int){
//Outer loop controls number of rows
for i := 0; i <= rows; i++{
//First inner loop to print spaces before pyramid character
for k := 1; k <= rows-1; k++{
fmt.Println(" ") //Print spcaces
}
//Second inner loop to print pyramid characters
for j := 1; j<= (2*i-1); j++{
fmt.Print("*") // Print star
}
// Move to the next row
fmt.Println()
}
}
//Pseudocode
// 1. Input the number of rows, n
// 2. For each row i from 1 to n:
// a. Print (n - i) spaces
// b. Print (2 * i - 1) stars
// c. Move to the next line
// 3. End