C Program to Check if all digits of a number divide it

CServer Side ProgrammingProgramming

For a number n given, we need to find whether all digits of n divide it or not i.e. if a number is ‘xy’ then both x and y should divide it.


Input - 24 

Output - Yes 

Explanation  - 24 % 2 == 0, 24 % 4 == 0

Using conditional statements checking if each digit is non-zero and divides the number. We need to iterate over each digit of the number. And the check for the divisibility of the number for that number.


#include <stdio.h>
int main(){
   int n = 24;
   int temp = n;
   int flag=1;
   while (temp > 0){
      int r = n % 10;
      if (!(r != 0 && n % r == 0)){
      temp /= 10;
   if (flag==1)
      printf("The number is divisible by its digits");
      printf("The number is not divisible by its digits");
   return 0;


The number is divisible by its digits
Updated on 09-Aug-2019 12:33:53