
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C Program to Check if all digits of a number divide it
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.
Sample
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.
Example
#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)){ flag=0; } temp /= 10; } if (flag==1) printf("The number is divisible by its digits"); else printf("The number is not divisible by its digits"); return 0; }
Output
The number is divisible by its digits
- Related Articles
- PHP program to check if all digits of a number divide it
- Java Program to check if all digits of a number divide it
- Python Program for Check if all digits of a number divide it
- Check if all digits of a number divide it in Python
- C++ Program to check if a given number is Lucky (all digits are different)
- C Program to check if a number is divisible by sum of its digits
- C Program to check if a number is divisible by any of its digits
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array?
- C/C++ Program to check whether it is possible to make the divisible by 3 number using all digits in an array?
- Check if the frequency of all the digits in a number is same in Python
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Java Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Find count of digits in a number that divide the number in C++
- C++ Program to Check if it is a Sparse Matrix
- Check if a number is magic (Recursive sum of digits is 1) in C++

Advertisements