Print all numbers less than N with at | C ++ program to print all the numbers less than N which have at most 2 unique digits ; Function to generate all possible numbers ; If the number is less than n ; If the number exceeds ; Check if it is not the same number ; Function to print all numbers ; All combination of digits ; Print all numbers ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; set < int > st ; void generateNumbers ( int n , int num , int a , int b ) { if ( num > 0 && num < n ) st . insert ( num ) ; if ( num >= n ) return ; if ( num * 10 + a > num ) generateNumbers ( n , num * 10 + a , a , b ) ; generateNumbers ( n , num * 10 + b , a , b ) ; } void printNumbers ( int n ) { for ( int i = 0 ; i <= 9 ; i ++ ) for ( int j = i + 1 ; j <= 9 ; j ++ ) generateNumbers ( n , 0 , i , j ) ; cout << " The ▁ numbers ▁ are : ▁ " ; while ( ! st . empty ( ) ) { cout << * st . begin ( ) << " ▁ " ; st . erase ( st . begin ( ) ) ; } } int main ( ) { int n = 12 ; printNumbers ( n ) ; return 0 ; }