Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
add solution by Go leanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
joyboyid committed Oct 21, 2024
1 parent 5c574ce commit 1765536
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Beginner Level 📁/Alternating Square Pattern/solution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import "fmt"

func main() {
var N int
fmt.Print("Enter the number of lines to print: ")
fmt.Scan(&N)

count := 1
for i := 1; i <= N; i++ {
if i%2 == 1 {
// Print increasing numbers for odd rows
for j := 0; j < 5; j++ {
fmt.Printf("%d ", count)
count++
}
} else {
// Print decreasing numbers for even rows
temp := count + 4
for j := 0; j < 5; j++ {
fmt.Printf("%d ", temp)
temp--
}
count += 5
}
fmt.Println()
}
}

0 comments on commit 1765536

Please sign in to comment.