Smallest and Largest sum of two n | C ++ implementation of the approach ; Function to return the smallest sum of 2 n - digit numbers ; Function to return the largest sum of 2 n - digit numbers ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int smallestSum ( int n ) { if ( n == 1 ) return 0 ; return ( 2 * pow ( 10 , n - 1 ) ) ; } int largestSum ( int n ) { return ( 2 * ( pow ( 10 , n ) - 1 ) ) ; } int main ( ) { int n = 4 ; cout << " Largest ▁ = ▁ " << largestSum ( n ) << endl ; cout << " Smallest ▁ = ▁ " << smallestSum ( n ) ; return 0 ; }