- 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

# C Program to check if a number is divisible by any of its digits

Given a number n, task is to find that any of the digit in the number divides the number completely or not. Like we are given a number 128625 is divisible by 5 which is also present in the number.

## Example

Input: 53142 Output: yes Explanation: This number is divisible by 1, 2 and 3 which are the digits of the number Input: 223 Output: No Explanation: The number is not divisible by either 2 or 3

**The approach used below is as follows** −

- We will start from the unit place and take the unit place’s number.
- Check whether the number is divisible or not
- Divide the number with 10
- Goto step 1 until the number is 0

## Algorithm

Start In function int divisible(long long int n) Step 1-> Declare and initialize temp = n Step 2 -> Loop while n { Set k as n % 10 If temp % k == 0 then, Return 1 Set n = n/ 10 End loop Return 0 In Function int main() Step 1-> Declare and initialize n = 654123 Step 2-> If (divisible(n)) then, Print "Yes” Step 3-> Else Print "No”

## Example

#include <stdio.h> int divisible(long long int n) { long long int temp = n; // check if any of digit divides n while (n) { int k = n % 10; if (temp % k == 0) return 1; n /= 10; } return 0; } int main() { long long int n = 654123; if (divisible(n)) { printf("Yes

"); } else printf("No

"); return 0; }

## Output

If run the above code it will generate the following output −

Yes

- Related Articles
- C Program to check if a number is divisible by sum of its digits
- Write a C# program to check if a number is divisible by 2
- Check if any permutation of a large number is divisible by 8 in Python
- Check if any permutation of a number is divisible by 3 and is Palindromic in Python
- Check if any large number is divisible by 17 or not in Python
- Check if any large number is divisible by 19 or not in Python
- Check if a large number is divisible by 20 in C++
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array?
- C Program to Check if all digits of a number divide it
- Check if a number is divisible by all prime divisors of another number in C++
- Check if a number is divisible by 23 or not in C++
- Check if a number is divisible by 41 or not in C++
- C++ program to find largest or equal number of A whose sum of digits is divisible by 4
- C/C++ Program to check whether it is possible to make the divisible by 3 number using all digits in an array?
- Check if N is divisible by a number which is composed of the digits from the set {A, B} in Python

Advertisements