Home » C solved programs » C basic programs

# C program to check given number is divisible by A and B

In this C program, we will **read an integer number and check whether given integer number is divisible by A and B**. Here, A and B are the divisors given by the user.

Submitted by **IncludeHelp**, on March 27, 2018

Given an integer number ** number** and two divisors

**and**

*A***, we have to check whether number is divisible by A and B in C.**

*B***Example:**

Input: number = 100 A = 10, B = 20 Output: 100 is divisible by 10 and 20 Input: number = 90 A = 10, B = 20 Output: 90 is not divisible by 10 and 20

To check whether a given number is divisible by two divisors (A and B) or not, we are creating a function named CheckDivision() which will return 1, if number is divisible by both divisors else it will return 0.

**Function declaration:**

int CheckDivision(int num, int a , int b)

**Here,**

- int is the return type
- CheckDivision is the function name
- int num is the number to divide
- int a , int b are the divisors

**Statements with function calling:**

if(CheckDivision(number,A,B)) printf("%d is divisible by %d and %d\n",number,A,B); else printf("%d is not divisible by %d and %d\n",number,A,B);

Statement printf("%d is divisible by %d and %d\n",number,A,B); will be executed if function will return 1 else printf("%d is not divisible by %d and %d\n",number,A,B); will be executed.

## Program to check number is divisible by A and B in C

/** C program to check given number is divisible by A and B Here, A and B are integers */ #include <stdio.h> //function will return 1 if given number is //divisible by both numbers a and b int CheckDivision(int num, int a , int b) { //we have to check whether num is //divisible by a and b if( num%a==0 && num%b==0 ) return 1; else return 0; } // main function int main() { int number=0,A=0,B=0; printf("Enter any integer number : "); scanf("%d",&number); printf("Enter first divisor : "); scanf("%d",&A); printf("Enter second divisor : "); scanf("%d",&B); if(CheckDivision(number,A,B)) printf("%d is divisible by %d and %d\n",number,A,B); else printf("%d is not divisible by %d and %d\n",number,A,B); return 0; }

**Output**

Run 1 : Enter any integer number : 100 Enter first divisor : 10 Enter second divisor : 20 100 is divisible by 10 and 20 Run 2: Enter any integer number : 90 Enter first divisor : 10 Enter second divisor : 20 90 is not divisible by 10 and 20

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.