 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Advertisements
 