- 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

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.

- Initialise the numbers n and k.
- Find the remainder with modulo operator.
- If the remainder is zero, then return n.
- Else return n - remainder.

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.

- Related Questions & Answers
- Largest K digit number divisible by X in C++
- C++ Program for Largest K digit number divisible by X?
- Count numbers (smaller than or equal to N) with given digit sum in C++
- Find largest number smaller than N with same set of digits in C++
- C++ Program for the Largest K digit number divisible by X?
- Largest N digit number divisible by given three numbers in C++
- Java Program for Largest K digit number divisible by X
- Minimum numbers which is smaller than or equal to N and with sum S in C++
- Largest set with bitwise OR equal to n in C++
- Find nth number that contains the digit k or divisible by k in C++
- Euler’s Totient function for all numbers smaller than or equal to n in java
- Count elements smaller than or equal to x in a sorted matrix in C++
- Print all Jumping Numbers smaller than or equal to a given value in C++
- Find Largest Special Prime which is less than or equal to a given number in C++
- How to get the largest integer less than or equal to a number in JavaScript?

Advertisements