Navigation Bar

Program Generate all possible combinations of 1, 2 & 3



#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int a,b,c;
cout<<”All possible combinations are as: “;
for (a=1;a<=3;a++)                                                                                                            
{                   
for (b=1;b<=3;b++)
{
for (c=1;c<=3;c++)
{
                               cout<<a<<" "<<b<<" "<<c<<endl;
}
}
}
getch();
}


Output


All possible combinations are as:
1 1 1       1 2 1       1 3 1
1 1 2       1 2 2       1 3 2
1 1 3       1 2 3       1 3 3

2 1 1       2 2 1       2 3 1
2 1 2       2 2 2       2 2 2
2 1 3       2 2 3       2 3 3


3 1 1       3 2 1       3 3 1
3 1 2       3 2 2       3 3 2
3 1 3       3 2 3       3 3 3

No comments:

Post a Comment