Owen

Owen

  • NA
  • 3
  • 15.6k

Converting Pseudocode to C#

Mar 19 2012 7:26 PM
Hi,

I am new to programming. I am finding it very difficult, always did. But I am studying top down design and makes some sense to me.
I was reading one example that presented Pseudocode. I have tried so many time to convert it to C#, but I keep getting it wrong.

Can someone help me convert it to C# to give me a better understanding. Its just for my own benefit. Thank you for any help you can provide.

Comment Get the value for N

Output: "Please enter a positive integer: "

Input: N

If N <= 0 Then

    Output: N " isn't a perfect number."

    STOP

Endif

 

Comment Initialize sum of the divisors & divison

SumOfDivisors <-- 1

Candidate <-- 2

 

Comment Consider all possible divisors

While Candidate <= N / 2 Do

    R <-- N - (Truncate ( N / Candidate ) )* Candidate

    If R = 0 Then

         SumOfDivisors <-- SumOfDivisors + Candidate

    Endif

    Candidate <-- Candidate + 1

Endwhile

 

Comment Check the results

If SumOfDivisors = N Then

    Output: N " is a perfect number."

Else

    Output: N " isn't a perfect number."

Endif


Answers (2)