Tuesday, September 2, 2014

Generate all possible combinations of 1, 2 and 3 (using for loop)


Problem

create a program that generates all possible combinations of 1, 2 and 3 using for loop.

Solution - Code

#include<stdio.h>
int main()
{
 int i,j,k;
 for(i=1;i<=3;i++)
 {
  for(j=1;j<=3;j++)
  {
   {
   for(k=1;k>=3;k++)
    if(j==k)
    continue;
    printf("%d%d%d\n",i,j,k);
   }
   if(i==j)
   continue;
   printf("%d%d%d\n",i,j,k);
  }
 }
 system("pause");
 return 0;
}

Sample Output


generate combinations c language

2 comments :

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact