Write a program to generate all combinations of 1, 2 and 3 using for loop.
void main()
{
int x,y,z,a,b,c;
printf("Input 3 digits");
scanf("%d%d%d",&x,&y,&z);
a=0;
b=0;
c=0;
for(a=1;(a==x||a==y||a==z)&&a<=9;b++)
{
for(b=1;(b==x||b==y||b==z)&&b<=9;b++)
{
if(a==b)
continue;
for(c=1;(c==x||c==y||c==z)&&c<=9;c++)
{
if(c==a)
continue;
if(c==b)
continue;
printf("%d%d%d",a,b,c);
break;
}
}
}
}
Subscribe to:
Post Comments (Atom)
#include
ReplyDelete#include
void main(void)
{
int i, j, k;
for (i=1; i<=3; i++)
{
for (j=1; j<=3; j++)
{
for (k=1; k<=3; k++)
printf("\n%d %d %d", i, j, k);
}
}
getch();
}