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.)
My Solution is a recursive function with number as arguement
Recursive function(num)
i=0,num,sum=0;
Loop2:
sum=sum+(-1)^i * num%10;
num=num/10;
i++;
check if num =0, else repeat loop2
if num=0, exit from loop;
check if sum <11, else repeat the Recursive function(sum)
if sum < 11 & sum =0 , print "Yes -- Divisible by 11"
if -11 < sum <11 & sum!=0, print "No -- Not Divisible by 11"
Edited on January 3, 2008, 1:39 am
|
Posted by Praneeth
on 2008-01-03 01:02:06 |