- 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

# Find M-th number whose repeated sum of digits of a number is N in C++

In this problem, we are given two positive numbers N and M. Our task is to *find the M-th number whose repeated sum of digits of a number is N. *

**Problem description: **Here, we need to find the Mth number whose sum of digits till the sum becomes single digit is equal to N.

**Let’s take an example to understand the problem, **

**Input: **N = 4 M = 6

**Output: **49

## Solution Approach

A simple solution of the problem, is by finding all numbers and count the number whose sum of digits is N, and return m-th number.

Another solution to the problem is using formula to find M-th number whose sum of digits is equal to N,

*M-th number = (m-1)*9 + N*

## Program to illustrate the working of our solution,

## Example

#include <bits/stdc++.h> using namespace std; int main() { int n = 4, m = 6; int mNumber = (m - 1) * 9 + n; cout<<m<<"-th number whose repeated sum of digits of a number is "<<n<<" is "<<mNumber; return 0; }

## Output

6-th number whose repeated sum of digits of a number is 4 is 49

- Related Questions & Answers
- n-th number whose sum of digits is ten 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++
- Find a Number X whose sum with its digits is equal to N in C++
- Repeated sum of Number’s digits in JavaScript
- Recursive sum of digits of a number formed by repeated appends in C++
- Minimum number of squares whose sum equals to given number n
- Find smallest number with given number of digits and sum of digits in C++
- C++ program to find largest or equal number of A whose sum of digits is divisible by 4
- Find a positive number M such that gcd(N^M,N&M) is maximum in Python
- Find sum of digits in factorial of a number in C++
- Find the Largest number with given number of digits and sum of digits in C++
- N-th root of a number in C++
- Find numbers whose sum of digits equals a value
- Program to count number of consecutive lists whose sum is n in C++
- Maximum sum and product of the M consecutive digits in a number in C++

Advertisements