
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Minimum positive integer divisible by C and is not in range [A, B] in C++
Suppose 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. Let us see the 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
- Maximum positive integer divisible by C and is in the 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
- Minimum positive integer required to split the array equally in C++
- For any positive integer n, prove that $n^3-n$ is divisible by 6.
- Number is divisible by 29 or not in C++
- Count numbers in range 1 to N which are divisible by X but not by Y in C++
- Program to find first positive missing integer in range in Python
- Find permutation of n which is divisible by 3 but not divisible by 6 in C++
- Minimum value that divides one number and divisible by other in C++
- Number of substrings divisible by 8 and not by 3 in C++
- Smallest Integer Divisible by K in Python
- An integer is chosen at random between 1 and 100. Find the probability that it is :$ ( i)$ divisible by 8 $( ii) $not divisible by 8
- Find the Numbers that are not divisible by any number in the range [2, 10] using C++
- Count the numbers divisible by ‘M’ in a given range in C++
- Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++

Advertisements