C program for generating all combinations of 1, 2 and 3
#include<stdio.h>
int comb(int a,int b,int c)/*defining function with parameters a,b and c of int type*/
{
for (a=1; a<4; a++) //loop for the first integer
{
for (b=1;b<4; b++) //loop for the second integer
{
for (c=1; c<4; c++) //loop for the third integer
printf("One of the combination is \\%d %d %d", a, b, c);
}
}
return 0;
}
int main()//driver function
{
int a, b, c;
printf("Combinations are-");
comb(a,b,c);//calling function
return 0;
}
Output
Combinations are-
One of the combination is 1 1 1
One of the combination is 1 1 2
One of the combination is 1 1 3
One of the combination is 1 2 1
One of the combination is 1 2 2
One of the combination is 1 2 3
One of the combination is 1 3 1
One of the combination is 1 3 2
One of the combination is 1 3 3
One of the combination is 2 1 1
One of the combination is 2 1 2
One of the combination is 2 1 3
One of the combination is 2 2 1
One of the combination is 2 2 2
One of the combination is 2 2 3
One of the combination is 2 3 1
One of the combination is 2 3 2
One of the combination is 2 3 3
One of the combination is 3 1 1
One of the combination is 3 1 2
One of the combination is 3 1 3
One of the combination is 3 2 1
One of the combination is 3 2 2
One of the combination is 3 2 3
One of the combination is 3 3 1
One of the combination is 3 3 2
One of the combination is 3 3 3