Write a Go Program to Print Rectangle Number Pattern of 1’s. In this Golang Rectangle Number pattern example, the nested for loop iterates rectangle rows and columns and prints ones as an output.
package main import "fmt" func main() { var i, j, recRow, recCol int fmt.Print("Enter the Rows to Print Rectangle of 1's = ") fmt.Scanln(&recRow) fmt.Print("Enter the Columns to Print Rectangle of 1's = ") fmt.Scanln(&recCol) fmt.Println("Rectangle Pattern of 1's") for i = 0; i < recRow; i++ { for j = 0; j < recCol; j++ { fmt.Print("1 ") } fmt.Println() } }
Golang Program to Print Rectangle Number Pattern of 0’s
In this Rectangle Number Pattern example, we replaced 0 with 1.
package main import "fmt" func main() { var i, j, recRow, recCol int fmt.Print("Enter the Rows to Print Rectangle of 0's = ") fmt.Scanln(&recRow) fmt.Print("Enter the Columns to Print Rectangle of 0's = ") fmt.Scanln(&recCol) fmt.Println("Rectangle Pattern of 0's") for i = 0; i < recRow; i++ { for j = 0; j < recCol; j++ { fmt.Print("0 ") } fmt.Println() } }
Enter the Rows to Print Rectangle of 0's = 6
Enter the Columns to Print Rectangle of 0's = 15
Rectangle Pattern of 0's
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
This Go program allows entering any number and prints that number in a Rectangle pattern.
package main import "fmt" func main() { var i, j, recRow, recCol, num int fmt.Print("Enter the Rows to Print Rectangle of 1's = ") fmt.Scanln(&recRow) fmt.Print("Enter the Columns to Print Rectangle of 1's = ") fmt.Scanln(&recCol) fmt.Print("Enter any Number to Print as Rectangle = ") fmt.Scanln(&num) fmt.Println("Rectangle Pattern of 1's") for i = 0; i < recRow; i++ { for j = 0; j < recCol; j++ { fmt.Printf("%d ", num) } fmt.Println() } }
Enter the Rows to Print Rectangle of 1's = 8
Enter the Columns to Print Rectangle of 1's = 22
Enter any Number to Print as Rectangle = 8
Rectangle Pattern of 1's
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8