Program: 106
Write a c program to generate all combinations of 1, 2 and 3 using for loop.
#include<stdio.h> #include<conio.h> int main() { int i, j, k; //for three numbers 1, 2 and 3 for(i=1;i<=3;i++){ for(j=1;j<=3;j++){ for(k=1;k<=3;k++){ //First Method //printf("%d%d%d\n", i, j, k); //Second Method //for removing repeated numbers we have to apply a condition (using if) if(i!=j && i!=k && j!=k){ printf("%d%d%d\n", i, j, k); } } } } }
Output:
123
132
213
231
312
321
Leave a Comment