Write a C program to check whether a number is divisible by 5 and 11 or not using if else. How to check divisibility of any number in C programming. C program to enter any number and check whether it is divisible by 5 and 11 or not.

Input number: 55

Output: Number is divisible by 5 and 11

5 % 2 = 1 (Since 5/2 leaves 1 as remainder)

2 % 5 = 2 (Since 5 goes in 0 times leaving remainder 2)

8 % 2 = 0 (Since 8/2 leaves 0 as remainder)

We also know that any number is divisible by other number if and only if it clearly divides the number leaving 0 remainder. Hence, if the modulus division on any number with 5 evaluates to 0 then the number is clearly divisible by 5 and so on you can check divisibility by other.

Happy coding ;)

**Example:**Input number: 55

Output: Number is divisible by 5 and 11

### Required knowledge

Basic programming, If else### Logic to check divisibility

In C programming divisibility of any number can be checked using %(Modulus operator). We know that modulus operator returns remainder i.e. The following operation returns:5 % 2 = 1 (Since 5/2 leaves 1 as remainder)

2 % 5 = 2 (Since 5 goes in 0 times leaving remainder 2)

8 % 2 = 0 (Since 8/2 leaves 0 as remainder)

We also know that any number is divisible by other number if and only if it clearly divides the number leaving 0 remainder. Hence, if the modulus division on any number with 5 evaluates to 0 then the number is clearly divisible by 5 and so on you can check divisibility by other.

### Program to check divisibility

/** * C program to check divisibility of any number */ #include <stdio.h> int main() { int num; /* Reads number from user */ printf("Enter any number: "); scanf("%d", &num); if((num%5 == 0) && (num%11 == 0) ) { printf("Number is divisible by 5 and 11"); } else { printf("Number is not divisible by 5 and 11"); } return 0; }

Output

Enter any number: 55

Number is divisible by 5 and 11

Number is divisible by 5 and 11

Happy coding ;)

### You may also like

- If else programming exercises index.
- C program to find maximum between three numbers.
- C program to check whether a number is positive, negative or zero.
- C program to enter two number and perform all arithmetic operations.
- C program to check leap year.
- C program to enter any number and check whether it is even or odd.
- C program to find whether a triangle is valid or not if angles of triangle are given.
- C program to enter any character and check whether it is alphabet, digit or special character.
- C program to enter month number and print number of days it contains.
- C program to count total number of notes in given amount.
- C program to print all even numbers between 1 to n.

Thanks for nice post.know details

ReplyDelete