Home > Algorithms
Divisible by 11 (Posted on 2008-01-02) |
|
Give an algorithm that determines whether a given number is divisible by 11 or not. The number could have up to one million digits.
(Note that simply dividing by 11, or doing long division by 11 is not allowed as a solution.)
|
Submitted by Chesca Ciprian
|
Rating: 3.0000 (2 votes)
|
|
Solution:
|
(Hide)
|
A number is divisible by 11 if the diference between sum of the digits from odd position and the digits from even position are divisible by 11.
n=123456789 s1=1+3+5+7+9=25 s2=2+4+6+8=20 s1-s2=5 so the number is not divisible by 11.
n=1122334455 s1=1+2+3+4+5 s1=1+2+3+4+5 s1-s2=0 so the number is divisible by 11.
The algorithm read from a file the digits of a "long number" char after char, calculate the sums and determine if the number is divisible by 11. |
Comments: (
You must be logged in to post comments.)
|
|
Please log in:
Forums (1)
Newest Problems
Random Problem
FAQ |
About This Site
Site Statistics
New Comments (6)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On
Chatterbox:
|