Given a number N, the task is to find the required numbers consist of only 0 and 1 digit whose sum is equal to N.
Input: 9 Output: 1 1 1 1 1 1 1 1 1 Only numbers smaller than or equal to 9 with digits 0 and 1 only are 0 and 1 itself. So to get 9, we have to add 1 - 9 times. Input: 31 Output: 11 10 10
- Initialize product p to 1 and m to zero.
- Create the vector that stores the resultant integer counts of 0s and 1s.
- Loop for N and check if N is multiple of 10 if yes get the decimal and update p by multiplying 10 and store this value in a vector and decrease N by m do this for each decimal and print the total size of vector.
- Finally traverse the vector and print the elements.
Below is the implementation of the above approach.
11 10 10
- Print all numbers less than N with at-most 2 unique digits
- Print all n-digit numbers whose sum of digits equals to given sum
- Recursive program to print all numbers less than N which consist of digits 1 or 3 only
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1
- Print prime numbers with prime sum of digits in an array
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Print first k digits of 1/n where n is a positive integer
- Print last k digits of a^b (a raised to power b)
- Print a number containing K digits with digital root D
- Print individual digits as words without using if or switch
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Java ArrayList to print all possible words from phone digits
- Compute sum of digits in all numbers from 1 to n
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.