Showing posts with label Combinations of 1. Show all posts
Showing posts with label Combinations of 1. Show all posts

Thursday, 15 November 2012

Program to print all combinations of numbers 1,2,3.



#include <stdio.h>
main()
{

int iter1=0,iter2=0,iter3=0;
for(iter1=1; iter1<=3; iter1++)
{
for(iter2=1; iter2<=3; iter2++)
{
for(iter3=1; iter3<=3; iter3++)
{
if(iter1 != iter2 && iter2 != iter3 && iter1 != iter3)
{
printf("%d %d %d \n",iter1, iter2, iter3);
}
}
}
}

return 0;
}


OUTPUT:



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