This C programming example is to check whether a given number is divisible by 3 or not. You can achieve this by applying multiple programming logic. Here, modulus operator (%) is used to find out if entered number is divisible by 3.
C program to check if a number is divisible by 3 - Source code
if ((number % 3) == 0)
printf("%d is a multiple of 3",number);
printf("%d is not a multiple of 3",number);
493648 is not a multiple of 3
98274651 is a multiple of 3
1. This program simply asks user to input an integer number.
2. In order to check for its divisibility by 3, modulus operator (%) is used. This operator return the remainder after dividing the given number by another number.
3. If the modulus operator return 0 as remainder, the number is multiple of 3. Otherwise, it is not a multiple of 3.