Print a number containing K digits with digital root D | C ++ implementation of the above approach ; Function to find a number ; If d is 0 k has to be 1 ; Print k - 1 zeroes ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printNumberWithDR ( int k , int d ) { if ( d == 0 && k != 1 ) cout << " - 1" ; else { cout << d ; k -- ; while ( k -- ) cout << "0" ; } } int main ( ) { int k = 4 , d = 4 ; printNumberWithDR ( k , d ) ; return 0 ; }