Minimize the sum of digits of A and B such that A + B = N | C ++ implementation of the approach ; Function to return the minimum possible sum of digits of A and B such that A + B = n ; Find the sum of digits of n ; If num is a power of 10 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minSum ( int n ) { int sum = 0 ; while ( n > 0 ) { sum += ( n % 10 ) ; n /= 10 ; } if ( sum == 1 ) return 10 ; return sum ; } int main ( ) { int n = 1884 ; cout << minSum ( n ) ; return 0 ; }