C Programming

Solved Example

Practice Questions

Exercise Question

Print all combination of 1,2, and 3

Objective

Write a c program to print all the combination of 1,2, and 3

Program

#include "stdio.h"
int main() {
	int i,j,k;
	
	for(i = 1; i <= 3; i++) { //first digit loop
		for(j = 1; j <= 3; j++) { //second digit loop
			for(k = 1; k <= 3; k++) { //third digit loop
				printf("%d%d%d\t",i,j,k);
			}
		}
	}
	
	return 0;
}

Output

111     112     113     121     122     123     131     132     133     211     212     213     221     222     223
        231     232     233     311     312     313     321     322     323     331     332     333