

- 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 count of digits in a number that divide the number in C++
Suppose a number is given. We have to count number of digits of the number which evenly divides the number. Suppose the number is 1012, the result is 3. There are three digits 1, 1, and 2 that evenly divide 1012.
To solve this, we will find each digit of the number, using modulus operation, and check whether the number is divisible by that digit or not, if divisible, then increase counter. If the digit is 0, then ignore that digit.
Example
#include<iostream> using namespace std; int countDivDigit(int num) { int count = 0; int temp = num; while(temp){ int div = temp%10; if(div != 0){ if(num % div == 0) count++; } temp /= 10; } return count; } int main() { int num = 1012; cout << "Number of digits that divides " << num << " evenly, is: " << countDivDigit(num); }
Output
Number of digits that divides 1012 evenly, is: 3
- Related Questions & Answers
- Number of digits that divide the complete number in JavaScript
- Count digits in given number N which divide N in C++
- Count number of ways to divide a number in parts in C++
- Golang Program to Count the Number of Digits in a Number
- Find maximum number that can be formed using digits of a given number in C++
- Count number of digits after decimal on dividing a number in C++
- Find the Largest number with given number of digits and sum of digits in C++
- Find the number of ways to divide number into four parts such that a = c and b = d in C++
- Program to count number of elements in a list that contains odd number of digits in Python
- Find smallest number with given number of digits and sum of digits in C++
- Check if all digits of a number divide it in Python
- C Program to Check if all digits of a number divide it
- Find sum of digits in factorial of a number in C++
- Number of digits in the nth number made of given four digits in C++
- Find the largest number that can be formed with the given digits in C++
Advertisements