Find the Number which contain the digit d | CPP program to print the number which contain the digit d from 0 to n ; function to display the values ; Converting d to character ; Loop to check each digit one by one . ; initialize the string ; checking for digit ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printNumbers ( int n , int d ) { string st = " " ; st += to_string ( d ) ; char ch = st [ 0 ] ; string p = " " ; p += ch ; for ( int i = 0 ; i <= n ; i ++ ) { st = " " ; st = st + to_string ( i ) ; int idx = st . find ( p ) ; if ( i == d idx != -1 ) cout << ( i ) << " ▁ " ; } } int main ( ) { int n = 100 , d = 5 ; printNumbers ( n , d ) ; }