
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Combinations Generator
Numbers are: a, b and c => 1, 2, 3
Combination of (a, b, c) are: (1, 1, 1), (1, 2, 1), (1, 2, 2), (1, 2, 3), . . ., (3, 3, 3).
Steps
- Define the variables, a, b and c.
- Print statement for the first number and scan the number.
- Print statement for the second number and scan the number.
- Print statement for the third number and scan the number.
- Initialize an array with numbers, a, b and c.
- Iterate the array with iterator i, j and k.
- Print (i, j, k)th index number of the array.
Example
package main import "fmt" func main(){ var a, b, c int fmt.Print("Enter first number: ") fmt.Scanf("%d", &a) fmt.Print("Enter second number: ") fmt.Scanf("%d", &b) fmt.Print("Enter third number: ") fmt.Scanf("%d", &c) arr := [3]int{a, b, c} for i := range arr{ for j := range arr{ for k := range arr{ fmt.Println(arr[i], arr[j], arr[k]) } } } }
Output
1 1 1 1 1 2 1 1 3 1 2 1 1 2 2 1 2 3 1 3 1 1 3 2 1 3 3 2 1 1 2 1 2 2 1 3 2 2 1 2 2 2 2 2 3 2 3 1 2 3 2 2 3 3 3 1 1 3 1 2 3 1 3 3 2 1 3 2 2 3 2 3 3 3 1 3 3 2 3 3 3
Advertisements