Given an integer **N**, the task is to print first **N** integers whose sum of digits is **10**.

**Examples:**

Input:N = 4

Output:19 28 37 46

Input:N = 6

Output:19 28 37 46 55 64

**Approach:** Initialise **num = 19** to get the first number of the series, now add **9** to the previous number and check whether the sum of the digits of the new number is **10**. If yes then this is the next number of the series, this is because the difference between any two consecutive numbers of the required series is **at least 9**.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the ` `// sum of digits of n ` `int` `sum(` `int` `n) ` `{ ` ` ` `int` `sum = 0; ` ` ` `while` `(n) { ` ` ` ` ` `// Add the last digit to the sum ` ` ` `sum = sum + n % 10; ` ` ` ` ` `// Remove last digit ` ` ` `n = n / 10; ` ` ` `} ` ` ` ` ` `// Return the sum of digits ` ` ` `return` `sum; ` `} ` ` ` `// Function to print the first n numbers ` `// whose sum of digits is 10 ` `void` `firstN(` `int` `n) ` `{ ` ` ` ` ` `// First number of the series is 19 ` ` ` `int` `num = 19, cnt = 1; ` ` ` `while` `(cnt != n) { ` ` ` ` ` `// If the sum of digits of the ` ` ` `// current number is equal to 10 ` ` ` `if` `(sum(num) == 10) { ` ` ` ` ` `// Print the number ` ` ` `cout << num << ` `" "` `; ` ` ` `cnt++; ` ` ` `} ` ` ` ` ` `// Add 9 to the previous number ` ` ` `num += 9; ` ` ` `} ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 10; ` ` ` `firstN(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to return the ` `// sum of digits of n ` `static` `int` `sum(` `int` `n) ` `{ ` ` ` `int` `sum = ` `0` `; ` ` ` `while` `(n > ` `0` `) ` ` ` `{ ` ` ` ` ` `// Add the last digit to the sum ` ` ` `sum = sum + n % ` `10` `; ` ` ` ` ` `// Remove last digit ` ` ` `n = n / ` `10` `; ` ` ` `} ` ` ` ` ` `// Return the sum of digits ` ` ` `return` `sum; ` `} ` ` ` `// Function to print the first n numbers ` `// whose sum of digits is 10 ` `static` `void` `firstN(` `int` `n) ` `{ ` ` ` ` ` `// First number of the series is 19 ` ` ` `int` `num = ` `19` `, cnt = ` `1` `; ` ` ` `while` `(cnt != n) ` ` ` `{ ` ` ` ` ` `// If the sum of digits of the ` ` ` `// current number is equal to 10 ` ` ` `if` `(sum(num) == ` `10` `) ` ` ` `{ ` ` ` ` ` `// Print the number ` ` ` `System.out.print(num + ` `" "` `); ` ` ` `cnt++; ` ` ` `} ` ` ` ` ` `// Add 9 to the previous number ` ` ` `num += ` `9` `; ` ` ` `} ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `n = ` `10` `; ` ` ` `firstN(n); ` `} ` `} ` ` ` `// This code is contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to return the ` `# sum of digits of n ` `def` `sum` `(n) : ` ` ` ` ` `sum` `=` `0` `; ` ` ` `while` `(n) : ` ` ` ` ` `# Add the last digit to the sum ` ` ` `sum` `=` `sum` `+` `n ` `%` `10` `; ` ` ` ` ` `# Remove last digit ` ` ` `n ` `=` `n ` `/` `/` `10` `; ` ` ` ` ` `# Return the sum of digits ` ` ` `return` `sum` `; ` ` ` `# Function to print the first n numbers ` `# whose sum of digits is 10 ` `def` `firstN(n) : ` ` ` ` ` `# First number of the series is 19 ` ` ` `num ` `=` `19` `; cnt ` `=` `1` `; ` ` ` ` ` `while` `(cnt !` `=` `n) : ` ` ` ` ` `# If the sum of digits of the ` ` ` `# current number is equal to 10 ` ` ` `if` `(` `sum` `(num) ` `=` `=` `10` `) : ` ` ` ` ` `# Print the number ` ` ` `print` `(num,end` `=` `" "` `); ` ` ` `cnt ` `+` `=` `1` `; ` ` ` ` ` `# Add 9 to the previous number ` ` ` `num ` `+` `=` `9` `; ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `n ` `=` `10` `; ` ` ` `firstN(n); ` ` ` `# This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to return the ` `// sum of digits of n ` `static` `int` `sum(` `int` `n) ` `{ ` ` ` `int` `sum = 0; ` ` ` `while` `(n > 0) ` ` ` `{ ` ` ` ` ` `// Add the last digit to the sum ` ` ` `sum = sum + n % 10; ` ` ` ` ` `// Remove last digit ` ` ` `n = n / 10; ` ` ` `} ` ` ` ` ` `// Return the sum of digits ` ` ` `return` `sum; ` `} ` ` ` `// Function to print the first n numbers ` `// whose sum of digits is 10 ` `static` `void` `firstN(` `int` `n) ` `{ ` ` ` ` ` `// First number of the series is 19 ` ` ` `int` `num = 19, cnt = 1; ` ` ` `while` `(cnt != n) ` ` ` `{ ` ` ` ` ` `// If the sum of digits of the ` ` ` `// current number is equal to 10 ` ` ` `if` `(sum(num) == 10) ` ` ` `{ ` ` ` ` ` `// Print the number ` ` ` `Console.Write(num + ` `" "` `); ` ` ` `cnt++; ` ` ` `} ` ` ` ` ` `// Add 9 to the previous number ` ` ` `num += 9; ` ` ` `} ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `int` `n = 10; ` ` ` `firstN(n); ` `} ` `} ` ` ` `// This code is contributed by PrinciRaj1992 ` |

*chevron_right*

*filter_none*

**Output:**

19 28 37 46 55 64 73 82 91

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Find any K distinct odd integers such that their sum is equal to N
- Possible values of Q such that, for any value of R, their product is equal to X times their sum
- Find three integers less than or equal to N such that their LCM is maximum
- Count of pairs in a given range with sum of their product and sum equal to their concatenated number
- Find K consecutive integers such that their sum is N
- Count pairs from 1 to N such that their Sum is divisible by their XOR
- Queries to count integers in a range [L, R] such that their digit sum is prime and divisible by K
- Find the pair (a, b) with minimum LCM such that their sum is equal to N
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Print numbers with digits 0 and 1 only such that their sum is N
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Check if the sum of distinct digits of two integers are equal
- Find K numbers with sum equal to N and sum of their squares maximized
- Minimum number of primes required such that their sum is equal to N
- Find the number of sub arrays in the permutation of first N natural numbers such that their median is M
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Find two numbers such that difference of their squares equal to N
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Find a number x such that sum of x and its digits is equal to given n.
- Find two co-prime integers such that the first divides A and the second divides B

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.