This is the program in pseudo-code. I'm looking for criticism to the design of the program and my pseudo-coding technique
Code:
Conventions
1. := denotes an assignment e.g. x:=6
2. == <= => < and > are comparison operators: equals, less than or equals, greater than or equals, less than, greater than, respectively
3. % denotes modulus operator e.g. 15%4 is 3
Function main
Terms and conditions
0.1 this function called first
0.2 assume num is a positive integer
START
1.if(num == 2 OR num == 3 OR isPrime(num)) then
1.1 output “num is prime”
1.2 GOTO END
1.3 end if
2.doFactor(num, 2)
3.doFactor(num, 3)
4.set sqrtOfNum := sqrt(floor(num))
5.set i := 5
6. while(i <= sqrtOfNum) do
6.1 set i:=i+2
6.2 if(isPrime(i)) then
6.3 .1 doFactor(num, i)
6.3.2 if(num == 1 OR isPrime(num)) then
6.3.2.1 if(num ≠ 1) then
6.3.2.2 display num
6.3.2.3 end if
6.3.3 GOTO END
6.3.4 end if
6.4 end if
7. end while
8. END
Function isPrime
argument: maybePrime
return: true iff maybePrime is prime, otherwise false
Terms and Conditions
0.1 assume maybePrime is a positive integer
START
1. set sqrtOfMaybePrime := floor(sqrt(maybePrime))
2. set j := 3
3. while(j <= sqrtOfMaybePrime) do
3.1 set j:=j+2
3.2 if(maybePrime%j == 0) then
3.2.1 return false
3.2.2 GOTO END
3.2.3 end if
3.3 return true
4. end while
5. END
Function doFactor
arguments: &num, determinedToBePrime
return: none
Terms and Conditions
0.1 num is passed by reference such that any changes made to it in this function, will still hold once this function has returned
0.2 assume num is a positive integer that is to be factored
0.3 assume determinedToBePrime is a positive integer that has been established to be prime
START
1. while(num%determinedToBePrime == 0) do
1.1 set num := num/determinedToBePrime
1.2 display “determinedToBePrime”
2. end while
3.END
well if anyone cares I found the answer to my question here