- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

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

# C++ code to find greater number whose factor is k

Suppose we have two numbers n and k. We have to find smallest integer x which is greater than n and divisible by k.

So, if the input is like n = 5; k = 3, then the output will be 6.

## Steps

To solve this, we will follow these steps −

return n + k - (n mod k)

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; int solve(int n, int k){ return n + k - n % k; } int main(){ int n = 5; int k = 3; cout << solve(n, k) << endl; }

## Input

5, 3

## Output

6

- Related Questions & Answers
- Program to find number of K-Length sublists whose average is greater or same as target in python
- C++ code to find out which number can be greater
- Count of subarrays whose maximum element is greater than k in C++
- C++ code to find composite numbers whose difference is n
- C++ code to find palindrome string whose substring is S
- C++ code to find three numbers whose sum is n
- C++ Program to find Number Whose XOR Sum with Given Array is a Given Number k
- Find the Minimum Number of Fibonacci Numbers Whose Sum Is K in C++
- Program to find number of consecutive subsequences whose sum is divisible by k in Python
- Program to count number of paths whose sum is k in python
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k in C++
- Find N distinct numbers whose bitwise Or is equal to K in Python
- Find N distinct numbers whose bitwise Or is equal to K in C++
- Find smallest element greater than K in Python
- Program to find out the number of consecutive elements in a matrix whose gcd is greater than 1 in Python

Advertisements