Tom Drayton

Tom Drayton

  • NA
  • 3
  • 4.1k

Converting pseudocode to C#

Mar 26 2020 1:43 AM
Does anyone know how to translate the pseudocode below into proper C# code. It is for a forms application where the program outputs all prime numbers between two integer values that are inputed into text boxes. Thanks in advance .
 
Begin
Clear list box
Initialise num1 and num2
Initialise noPrimes
Validate num1 and num2 as integers (exit if invalid)
If (num1 > num2)
exit
End if
For i = num1 to num2
Initialise count
For j = 2 to (square root of i)
If j is a factor i
Count++
Break out of inner for loop
End if
Next j
If count = 0
Increment noPrimes
Output i as a prime number
End if
Next I
Output the number of primes to the status bar
End
 
The forms application looks like this
 
 

Answers (3)