- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this tutorial, we are going to write a program that finds the n-th numbers whose digits sum is ten.

Let's see the sequence of number whose digits sum is 10.

19, 28, 37, 46, 55, etc..,

Each number is incremented by 9 in the above sequence. There are numbers in the above sequence whose digits sum does not equal 10. So, we can have a loop that increments by 9 and checks for digits sum and finds the n-th number.

Let's see the steps to solve the problem.

- Initialise the number
**n** - Initialise a counter to 0.
- Write a loop that iterates from
**19**- If the current number digits sum is 10, increment the counter by 1.
- If the counter is equal to n, then return the current number.
- Increment the iterative variable by 9.

Let's see the code.

#include <bits/stdc++.h> using namespace std; int findNthNumber(int n) { int count = 0, i = 19; while (true) { int sum = 0; for (int number = i; number > 0; number = number / 10) { sum = sum + number % 10; } if (sum == 10) { count++; } if (count == n) { return i; } i += 9; } return -1; } int main() { int n = 7; cout << findNthNumber(7) << endl; return 0; }

If you run the above code, then you will get the following result.

73

If you have any queries in the tutorial, mention them in the comment section.

- Related Questions & Answers
- Find M-th number whose repeated sum of digits of a number is N in C++
- Find a Number X whose sum with its digits is equal to N in C++
- Count of n digit numbers whose sum of digits equals to given sum in C++
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M in C++
- Program to count number of consecutive lists whose sum is n in C++
- Print all n-digit numbers whose sum of digits equals to given sum in C++
- N’th palindrome of K digits in C++
- Minimum number of single digit primes required whose sum is equal to N in C++
- Minimum number of squares whose sum equals to given number n
- N-th Tribonacci Number in C++
- N-th polite number in C++
- N-th root of a number in C++
- Number of arrays of size N whose elements are positive integers and sum is K in C++
- Number of pairs whose sum is a power of 2 in C++
- Find n-th Fortunate Number in C++

Advertisements