- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Maximum positive integer divisible by C and is in the range [A, B] in C++

Here we will see one interesting problem. let us consider we have three integers A, B, and C. We have to find one minimum integer X, such that X mod C = 0, and X is not in the range [A, B]. If the values of A, B and C are 5, 10 and 4 respectively, then the value of X will be 4. We have to follow these steps to get the solution −

**Steps −**

If C is not in the range [A, B], then return C as a result

Otherwise get the first multiple of C, which is greater than B, then return that value

## Example

#include <iostream> using namespace std; int findMinMumber(int a, int b, int c) { if (c < a || c > b) return c; int res = ((b / c) * c) + c; return res; } int main() { int a = 2, b = 4, c = 2; cout << "Minimum number X: " << findMinMumber(a, b, c); }

## Output

Minimum number X: 6

- Related Articles
- Minimum positive integer divisible by C and is not in range [A, B] in C++
- Find the minimum positive integer such that it is divisible by A and sum of its digits is equal to B in Python
- Count the numbers divisible by ‘M’ in a given range in C++
- $n^2 - 1$ is divisible by 8, if $n$ is(A) an integer(B) a natural number(C) an odd integer(D) an even integer
- Find the sum of the first 40 positive integers divisible by (a) 3 (b) 5 (c) 6.
- (a) Write a negative integer and a positive integer whose sum is $-5$.(b) Write a negative integer and a positive integer whose difference is $-3$.
- For any positive integer n, prove that $n^3-n$ is divisible by 6.
- Count numbers in a range that are divisible by all array elements in C++
- (a) Write a pair of negative integers whose difference gives $8$.(b) Write a negative integer and a positive integer whose sum is $-5$.(c) Write a negative integer and a positive integer whose difference is $-3$.
- Maximum and Minimum element of a linked list which is divisible by a given number k in C++
- Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++
- Minimum positive integer value possible of X for given A and B in X = P*A + Q*B in C++
- Count of Numbers in a Range divisible by m and having digit d in even positions in C++
- Program to find first positive missing integer in range in Python
- Find Positive Integer Solution for a Given Equation in C++

Advertisements