Last active
January 9, 2017 05:31
-
-
Save hygull/265ee354adf6e3ddf2d5a70e68593880 to your computer and use it in GitHub Desktop.
Go - To print binary combinations created by hygull - https://repl.it/FD9l/2
This file contains hidden or 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
| /* | |
| #Date of creation : 9 Jan 2016. | |
| #Aim of program : To print binary combinations. | |
| #Coded by : Rishikesh Agrawani. | |
| */ | |
| package main | |
| import "fmt" | |
| func main() { | |
| var n, r, i, j uint | |
| fmt.Print("Enter the number of binary variables: ") | |
| fmt.Scanf("%d", &n) | |
| r = 1 | |
| for i = 1; i <= n; i++ { | |
| r *= 2 | |
| } | |
| fmt.Println("Columns => ", n, "\nRows => ", r) | |
| for i = 0; i < r; i++ { | |
| for j = 0; j < n; j++ { | |
| if (i>>j)&1 == 1 { | |
| fmt.Print("0 ") | |
| } else { | |
| fmt.Print("1 ") | |
| } | |
| } | |
| fmt.Println() | |
| } | |
| } | |
| /*1st RUN: | |
| Enter the number of binary variables: 3 | |
| Columns => 3 | |
| Rows => 8 | |
| 1 1 1 | |
| 0 1 1 | |
| 1 0 1 | |
| 0 0 1 | |
| 1 1 0 | |
| 0 1 0 | |
| 1 0 0 | |
| 0 0 0 | |
| */ | |
| /*2nd RUN: | |
| Enter the number of binary variables: 4 | |
| Columns => 4 | |
| Rows => 16 | |
| 1 1 1 1 | |
| 0 1 1 1 | |
| 1 0 1 1 | |
| 0 0 1 1 | |
| 1 1 0 1 | |
| 0 1 0 1 | |
| 1 0 0 1 | |
| 0 0 0 1 | |
| 1 1 1 0 | |
| 0 1 1 0 | |
| 1 0 1 0 | |
| 0 0 1 0 | |
| 1 1 0 0 | |
| 0 1 0 0 | |
| 1 0 0 0 | |
| 0 0 0 0 | |
| */ | |
| /*3rd RUN: | |
| Enter the number of binary variables: 6 | |
| Columns => 6 | |
| Rows => 64 | |
| 1 1 1 1 1 1 | |
| 0 1 1 1 1 1 | |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 0 0 0 0 0 | |
| 0 0 0 0 0 0 | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment