This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.
Q. Write a program to generate all combinations of 1, 2 and 3 using for loop.
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n1, n2, n3;
for(n1=1;n1<=3;n1++)
{
for(n2=1;n2<=3;n2++)
{
if(n1==n2)
continue;
for(n3=1;n3<=3;n3++)
{
if(n1==n3 || n2==n3)
continue;
printf("%d%d%d\n",n1,n2,n3);
}
}
}
getch();
}