- Related Questions & Answers
- Average numbers in array in C Programming
- Add minimum number to an array so that the sum becomes even in C programming
- Arithmetic Mean in C programming
- C/C++ Program for nth Catalan Number?
- C Program to Check if all digits of a number divide it
- Concatenate a string given number of times in C++ programming
- Write a program to Delete a Tree in C programming
- Write a function that returns 2 for input 1 and returns 1 for 2 in C programming
- Ways to paint N paintings such that adjacent paintings don’t have same colors in C programming
- Surface Area and Volume of Hexagonal Prism in C programming
- Superperfect Number in C programming
- Super Prime in c programming
- Sums of ASCII values of each word in a sentence in c programming
- Sum triangle from an array in C programming
- C Programming for sum of the series 0.6, 0.06, 0.006, 0.0006, …to n terms

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

Smallest K digit number that divisible by X is found using the formula by checking divisible by X. The formula works in the following way −

Compute minimum K digit number [min] for example: 10/100/1000 etc.

Now find if min is divisible by X. if yes, then this is the answer.

If not, then min+X - ([min+X]%k) is the answer.

#include <iostream> #include <math.h> using namespace std; int main() { int X = 83; int K = 5; cout<<"The smallest "<<K<<" digit number divisible by "<<X<<" is "; int MIN = pow(10, K - 1); if (MIN % X == 0) cout<<MIN; cout<<((MIN + X) - ((MIN + X) % X)); cout << answer(X, K); }

The smallest 5 digit number divisible by 83 is 100430

Advertisements