
- 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
C++ Program for the Largest K digit number divisible by X?
Two integers X and K are given. K is the number of digit in integer number. The logic is to find largest K-digit number divisible by X.
Input: X = 30, K = 3 Output: 980
Explanation
980 is the largest three digit number divisible by 30. By taking the K in power of 10 then subtracting it with 1 will give us the largest K digit number after that we will try to get the largest no. which is divided by X.
Example
#include <iostream> #include <math.h> using namespace std; int main() { int X = 20; int K = 3; int MAX = pow(10, K) - 1; cout << (MAX - (MAX % X)); }
- Related Articles
- C++ Program for Largest K digit number divisible by X?
- Java Program for Largest K digit number divisible by X
- Largest K digit number divisible by X in C++
- Python Program for Smallest K digit number divisible by X
- C++ Program for Smallest K digit number divisible by X?
- Java Program for Smallest K digit number divisible by X
- C++ Programming for Smallest K digit number divisible by X?
- Find the largest 4 digit number divisible by 16.
- Largest N digit number divisible by given three numbers in C++
- Find nth number that contains the digit k or divisible by k in C++
- Largest number smaller than or equal to N divisible by K in C++
- Is the digit divisible by the previous digit of the number in JavaScript
- Program to Find Out the Largest K-Divisible Subsequence Sum in Python
- Count n digit numbers divisible by given number in C++
- Determine the greatest four-digit number which is exactly divisible by 10,12,16.?

Advertisements