Given a number, the job is to find if the number is divisible through 9 or not. The entry number might be huge and it may not be feasible to store also if we use lengthy long int.Examples:Input : n = 69354Output : YesInput : n = 234567876799333Output : NoInput : n = 3635883959606670431112222Output : No
Since entry number might be very large, us cannot usage n % 9 to inspect if a number is divisible by 9 or not, particularly in languages choose C/C++. The idea is based on following fact.A number is divisible by 9 if sum of its number is divisible by 9.

You are watching: How to tell if a number is divisible by 9

Illustration:For instance n = 9432Sum of digits = 9 + 4 + 3 + 2 = 18Since amount is divisible through 9,answer is Yes.How does this work?


Let us take into consideration 1332, we can write it as1332 = 1*1000 + 3*100 + 3*10 + 2The proof is based upon below observation:Remainder the 10i divided by 9 is 1So strength of 10 just results in remainder 1 when split by 9.Remainder of "1*1000 + 3*100 + 3*10 + 2"divided by 9 deserve to be written as : 1*1 + 3*1 + 3*1 + 2 = 9The over expression is basically sum ofall digits.Since 9 is divisible by 9, prize is yes.Below is the implementation of above idea.

See more: How Long Does It Take To Run 1.5 Miles, Tips On Running 1


Output:YesThis short article is added by DANISH_RAZA . If you favor ubraintv-jp.com and would like to contribute, girlfriend can additionally write an article using contribute.ubraintv-jp.com or letter your post to contribute
ubraintv-jp.com. View your article appearing on the ubraintv-jp.com key page and aid other Geeks.Please compose comments if you uncover anything incorrect, or you want to share an ext information around the topic discussed above.Attention reader! Don’t stop learning now. Obtain hold of every the essential mathematical principles for competitive programming with the Essential Maths because that CP Course at a student-friendly price. To finish your ready from learning a language to DS Algo and also many more, you re welcome refer Complete Interview preparation Course.


https://media.ubraintv-jp.com/auth/avatar.png
Competitive Programming Live Classes because that Students
DSA me Paced Course
DSA Live classes for functioning Professionals
Program for factorial the a numberPrime NumbersProgram to find GCD or HCF of two numbersModulo Operator (%) in C/C++ v ExamplesProgram because that Decimal come Binary Conversion
Minimum variety of jumps to with endSieve that EratosthenesMerge two sorted arraysCounting SortWrite a regime to turning back digits the a number
We usage cookies come ensure you have actually the ideal browsing endure on ours website. By using our site, youacknowledge that you have actually read and understood ourCookie policy & Privacy PolicyGot that !