Check out example codes for "find smallest number whose sum of digits equal to n". It will help you in understanding the concepts better.

Code Example 1

``````// 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;
}``````

Code Example 2

``````// 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``````

Learn ReactJs, React Native from akashmittal.com