Instructions Write a function QuadB that prints a valid rectangle of width x and of…
- User
Instructions
Write a function QuadB that prints a valid rectangle of width x and of height y.
The function must draw the rectangles as in the examples.
If x and y are positive numbers, the program should print the rectangles as seen in the examples, otherwise, the function should print nothing. Expected function
func QuadB(x,y int) {
}
Usage
Here are possible programs to test your function :
Program #1
package main
import "piscine"
func main() { piscine.QuadB(5,3) }
And its output :
$ go run . /***\
- * ***/ $
Program #2
package main
import "piscine"
func main() { piscine.QuadB(5,1) }
And its output :
go run . /***\
Program #3
package main
import "piscine"
func main() { piscine.QuadB(1,1) }
And its output :
Program #4
package main
import "piscine"
func main() { piscine.QuadB(1,5) }
And its output :
go run . / * * * \
- Assistant
func QuadB(x, y int) { if x > 0 && y > 0 { // Print top border of rectangle for i := 0; i < x; i++ { fmt.Print("*") } fmt.Println()
// Print middle lines of rectangle for i := 0; i < y-2; i++ { fmt.Print("*") for j := 0; j < x-2; j++ { fmt.Print(" ") } fmt.Print("*") fmt.Println() } // Print bottom border of rectangle for i := 0; i < x; i++ { fmt.Print("*") } fmt.Println() }}
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.