

- 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 the Number which contain the digit d in C++
Consider we have a digit d, and the upper limit n. we have to find all numbers that contains d in range 0 to n. So if n = 20, and digit is 3, then the numbers will be [3, 13].
To solve this problem, we will take every number as string, then if the digit is present in the string, the number will be printed, otherwise ignored.
Example
#include<iostream> using namespace std; int getAllNumWithDigit(int n, int d) { string str = ""; str += to_string(d); char ch = str[0]; string p = ""; p += ch; for (int i = 0; i <= n; i++) { str = ""; str = str + to_string(i); int index = str.find(p); if (i == d || index!=-1) cout << (i) << " "; } } int main() { int n = 100; int d = 3; getAllNumWithDigit(n, d); }
Output
3 13 23 30 31 32 33 34 35 36 37 38 39 43 53 63 73 83 93
- Related Questions & Answers
- Find minimum possible digit sum after adding a number d in C++
- Find N digits number which is divisible by D in C++
- JavaScript - Find the smallest n digit number or greater
- Is the digit divisible by the previous digit of the number in JavaScript
- Find the frequency of a digit in a number using C++.
- C++ Program to find the smallest digit in a given number
- Java program to accept the strings which contain all vowels
- Which packages contain Wrapper class in Java?
- Find documents which contain a particular value in MongoDB using Regular Expressions?
- 8085 program to find minimum value of digit in the 8 bit number
- Finding the largest 5 digit number within the input number using JavaScript
- Find the largest palindrome number made from the product of two n digit numbers in JavaScript
- Find nth number that contains the digit k or divisible by k in C++
- Count ‘d’ digit positive integers with 0 as a digit in C++
- Suppress the rows and/or columns of a 2- D array that contain masked values in Numpy
Advertisements