Smallest number whose product with N has sum of digits equal to that of N | C # program for the above approach ; Function to find the minimum integer having sum of digits of a number multiplied by n equal to sum of digits of n ; Initialize answer ; Convert string to character array ; Find sum of digits of N ; Multiply N with x ; Sum of digits of the new number ; If condition satisfies ; Print answer ; Driver Code ; Function call
using System ; using System . Globalization ; class GFG { static void find_num ( string n ) { int ans = 0 ; char [ ] digitsOfN = n . ToCharArray ( ) ; int sumOfDigitsN = 0 ; foreach ( char c in digitsOfN ) { sumOfDigitsN += Int32 . Parse ( Char . ToString ( c ) ) ; } for ( int x = 11 ; x > 0 ; x ++ ) { int newNum = x * Int32 . Parse ( n ) ; int tempSumDigits = 0 ; string str = newNum . ToString ( ) ; char [ ] temp = str . ToCharArray ( ) ; foreach ( char c in temp ) { tempSumDigits += Int32 . Parse ( Char . ToString ( c ) ) ; } if ( tempSumDigits == sumOfDigitsN ) { ans = x ; break ; } } Console . WriteLine ( ans ) ; } public static void Main ( ) { string N = "3029" ; find_num ( N ) ; } }