- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a given number divides the sum of the factorials of its digits in C++
Suppose, we have an integer, we have to find if the number divides the sum of the factorial of its digits. Suppose a number is 19, the sum of factorial of digits is (1! + 9!) = 362881, this is divisible by 19.
To solve this, we will take the number, then calculate factorial of each digit and add the sum, if the sum is divisible by the number itself, then return true, otherwise false.
Example
#include <iostream> using namespace std; int factorial(int n){ if(n == 1 || n == 0) return 1; return factorial(n - 1) * n; } bool isDigitsFactDivByNumber(int num){ int temp = num; int sum = 0; while(num){ int digit = num % 10; sum += factorial(digit); num /= 10; }if(sum%temp == 0){ return true; } return false; } int main() { int number = 19; if (isDigitsFactDivByNumber(number)) cout << "Yes, the number can divides the sum of factorial of digits."; else cout << "No, the number can not divides the sum of factorial of digits."; }
Output
Yes, the number can divides the sum of factorial of digits.
- Related Articles
- C Program to check if a number is divisible by sum of its digits
- C++ Program to Sum the digits of a given number
- Find the Largest number with given number of digits and sum of digits in C++
- Find last two digits of sum of N factorials using C++.
- Check if a number is magic (Recursive sum of digits is 1) in C++
- Find smallest number with given number of digits and sum of digits in C++
- C Program to sum the digits of a given number in single statement
- C Program to check if a number is divisible by any of its digits
- A two digit number is 4 times the sum of its digits and twice the product of its digits. Find the number.
- Check if a given number can be represented in given a no. of digits in any base in C++
- A two-digit number is 4 times the sum of its digits. If 18 is added to the number, the digits are reversed. Find the number.
- The sum of digits of a two-digit number is 15. The number obtained by reversing the order of digits of the given number exceeds the given number by 9. Find the given number.
- Number of digits in the nth number made of given four digits in C++
- The sum of a two digit number and the number obtained by reversing the order of its digits is 99. If the digits differ by 3, find the number.
- A two-digit number is 4 times the sum of its digits and twice the product of the digits. Find the number.

Advertisements