Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
e.g.1)86=8^2+6^2=64+36=100+1^2+0^2+0^2=1 (If we get single digit as 1 then it is perfect number)
e.g2)2=2^2=4=4^2=16=1^2+6^2=1+36=37=3^2+7^2=9+49=58=5^2+8^2=25+64=89=8^2+9^2=64+81=145=1^2+4^2+5^2=1+16+25=42=4^2+2^2=16+4=20=2^2+0^2=4(it s repeating again so it is not perfect number)
Posted
Updated 25-Jun-15 21:22pm
v2
Comments
Suvendu Shekhar Giri 26-Jun-15 3:30am    
Anything you have tried so far?
Is it the logic to determine perfect number?
phil.o 26-Jun-15 4:47am    
What have you tried? Where are you stuck?

Go and try to define the algorithm in pseudo code, e.g.
function test(int value) return void
begin
    attempts = 100
    while (attempts > 0 && value > 1) do
        write_line("value: {1}", value)
        attempts--
        text = as_string(value)
        value = 0;
        for each char c in split_into_chars(text) do
            value += char_square_to_int(c)
        end for each
    end while
    write_line("ended with value {0}", value)
end function

function char_square_to_int(char c) return int
begin
    return as_int(c-'0') * as_int(c-'0')
end function
Transforming into C# is left as exercise.
Cheers
Andi
 
Share this answer
 
Well, that's smells of homework: you should do it, we can just help on specific problems.
Moreover, the algorithm looks pretty straighforward, what is your doubt about?
 
Share this answer
 
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900