Created
December 10, 2016 18:10
-
-
Save hygull/b3acba38fca6f50ec7c4b943897c23d6 to your computer and use it in GitHub Desktop.
To print X symbol using * characters created by hygull - https://repl.it/EmdA/4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
{ | |
"cretaed_after" : "Sat Dec 10 23:14:26 IST 2016" | |
"aim_of_program" : "To print X symbol using * characters" | |
"coded_by" : "Rishikesh Agrawani" | |
} | |
*/ | |
package main | |
import "fmt" | |
func main() { | |
var n int //var n int8 ... will generate an error | |
fmt.Print("Enter a number between 3-20 :\t") | |
fmt.Scanf("%d", &n) | |
if n > 2 && n < 21 { // 3 <= n <= 20 | |
for i := 0; i < n; i++ { //Outer for loop takes care about rows | |
for j := 0; j < n; j++ { //Inner for loop takes care about columns | |
if i == j || (i+j) == (n-1) { //Based on matrix concept we got these conditions | |
fmt.Print("*") | |
} else { | |
fmt.Print(" ") //In case when conditions don't match | |
} | |
} | |
fmt.Println() //Newline | |
} | |
} else { | |
fmt.Println("\nThe number should be in inclusive range [3-20]") | |
} | |
} | |
/* | |
admins-MacBook-Pro-3:GoFiles admin$ go run X.go | |
Enter a number between 3-10 : 5 | |
* * | |
* * | |
* | |
* * | |
* * | |
admins-MacBook-Pro-3:GoFiles admin$ go run X.go | |
Enter a number between 3-10 : 10 | |
* * | |
* * | |
* * | |
* * | |
** | |
** | |
* * | |
* * | |
* * | |
* * | |
admins-MacBook-Pro-3:GoFiles admin$ go run X.go | |
Enter a number between 3-10 : 23 | |
The number should be in inclusive range [3-10] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment