SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C program to print combination of 1 2 3
C program to print combination of 1 2 3
Output:
123
23
13
3
12
2
1
Implementation:
#include
int main(void) { /* enter the numbers in the array for which you want to find combinations */ int a[]={1,2,3}; /* determine the number of combinations 2^(number of elements) -1 here, =pow(2,3)-1(since, 3 elements are there,viz.,1,2,3) =8-1 =7 */ int s=7; int t; int i; while(s) { t=s; /* until the number of elements of the array change the condition according to your size of the array */ for(i=0;i<3;i++) { if(t&1) printf("%d",a[i]); t>>=1; } s--; printf("\n"); } return 0; }
PREVIOUS
NEXT
HOME