0
Q:

find smallest number whose sum of digits equal to n

// C++ program to find the smallest 
// number whose sum of digits is also N 
#include <iostream> 
#include <math.h> 
using namespace std; 
  
// Function to find the smallest 
// number whose sum of digits is also N 
void smallestNumber(int N) 
{ 
    cout << (N % 9 + 1) 
                    * pow(10, (N / 9)) 
                - 1; 
} 
  
// Driver code 
int main() 
{ 
    int N = 10; 
    smallestNumber(N); 
  
    return 0; 
} 
-1
// C# program to find the smallest 
// number whose sum of digits is also N 
using System; 
  
class GFG{ 
  
// Function to get sum of digits 
static int getSum(int n) 
{ 
    int sum = 0; 
    while (n != 0)  
    { 
        sum = sum + n % 10; 
        n = n / 10; 
    } 
    return sum; 
} 
  
// Function to find the smallest 
// number whose sum of digits is also N 
static void smallestNumber(int N) 
{ 
    int i = 1; 
    while (1 != 0)  
    { 
          
        // Checking if number has 
        // sum of digits = N 
        if (getSum(i) == N)  
        { 
            Console.Write(i); 
            break; 
        } 
        i++; 
    } 
} 
  
// Driver code 
public static void Main(String[] args) 
{ 
    int N = 10; 
      
    smallestNumber(N); 
} 
} 
  
// This code is contributed by Amit Katiyar 
0

New to Communities?

Join the community