In this tutorial, we are going to write a program that finds the number that is smaller than or equal to N and divisible by k.
Let's see the steps to solve the problem.
Let's see the code.
#include <bits/stdc++.h> using namespace std; int findLargerNumber(int n, int k) { int remainder = n % k; if (remainder == 0) { return n; } return n - remainder; } int main() { int n = 33, k = 5; cout << findLargerNumber(n, k) << endl; return 0; }
If you run the above code, then you will get the following result.
30
If you have any queries in the tutorial, mention them in the comment section.