Prime Number is one of the common question that programming question wants those starter to do.
[Purpose For Reference]
[Purpose For Reference]
C#
This is running from Visual Studio C# ASP.NET
Let's see, the work step of computer during progressing...
(1) Input 4
(2) for ( integer j = 0; j <= 4; j++)
A: Loop For (2) Step
(A*) set Boolean IsPrime = True (* mean every loop and it is constant)
(A2) for (integer p = 2; p < 0 ; p++) [ignored, condition is false]
(A2:1) if ( 0 % 2 == 0) then isPrime = false then break (false) [ignored, condition is false]
(A3) for (integer p = 2; p < 1 ; p++) [ignored, condition is false]
(A3:1) if ( 1 % 2 == 0) then isPrime = false then break (false) [ignored, condition is false]
(A4) for (integer p = 2; p < 2 ; p++) [ignored, condition is false]
(A4:1) if ( 2 % 2 == 0) then isPrime = false then break (true) [ignored, condition is false]
(A5) for (integer p = 2; p < 3 ; p++)
(A5:1) if ( 3 % 2 == 0) then isPrime = false then break (false)
(A5:2) if ( 3 % 3 == 0) then isPrime = false then break (true)
(A6) for (integer p = 2; p < 4 ; p++)
(A6:1) if ( 4 % 2 == 0) then isPrime = false then break (false)
(A6:2) if ( 4 % 3 == 0) then isPrime = false then break (true)
(A6:3) if ( 4 % 4 == 0) then isPrime = false then break (true)
So finally it is "(true)" which mean it is Prime.
No comments:
Post a Comment