# 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

Live Demo

#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
{"ft_lang_label":"__label__en","ft_lang_prob":0.7760965,"math_prob":0.993304,"size":3058,"snap":"2022-40-2023-06","text_gpt3_token_len":818,"char_repetition_ratio":0.21643746,"word_repetition_ratio":0.15654951,"special_character_ratio":0.2884238,"punctuation_ratio":0.04467354,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9991486,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-01-30T08:35:13Z\",\"WARC-Record-ID\":\"<urn:uuid:4dfe2d0f-a68f-4c41-a33e-79e8905cc700>\",\"Content-Length\":\"43945\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d2048183-92b4-4e8f-b6c9-30a6fb3f9a35>\",\"WARC-Concurrent-To\":\"<urn:uuid:e55abc92-31b9-4b73-91d5-855d6371ebad>\",\"WARC-IP-Address\":\"192.229.210.176\",\"WARC-Target-URI\":\"https://www.tutorialspoint.com/c-program-to-check-if-a-number-is-divisible-by-any-of-its-digits\",\"WARC-Payload-Digest\":\"sha1:3OD674U72YAZ5SYDHP4RJRRHROVRBVUF\",\"WARC-Block-Digest\":\"sha1:WVSDM6VU2KZPXS2NJAAHO36OQ7U7LZOD\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764499804.60_warc_CC-MAIN-20230130070411-20230130100411-00043.warc.gz\"}"}