Primality by trial division: Difference between revisions

Content deleted Content added
m →‎{{header|COBOL}}: Put in wrong place.
m →‎{{header|COBOL}}: Move to right position in examples.
Line 348:
endif(b)
endforeach(i)</lang>
 
=={{header|COBOL}}==
 
{{novice example|COBOL}}
 
<lang cobol>
Identification division.
Program-id. prime-div.
 
Data division.
Working-storage section.
 
* The number for which we are testing primality.
01 num pic 9(6) value 1.
01 out-num pic z(6).
 
* Division-related stuff.
01 div pic 9(6).
01 div-lim pic 9(6).
01 rem pic 9(6).
88 not-prime value 0.
 
Procedure division.
Main.
Perform until num = 0
perform get-a-num
perform is-prime
move num to out-num
if not-prime display out-num " is not prime."
else display out-num " is prime."
end-perform.
Stop run.
 
Is-prime.
Compute div-lim = function sqrt(num) + 1.
Perform
with test after
varying div from 2 by 1
until div = div-lim or not-prime
compute rem = function mod(num, div)
end-perform.
 
Get-a-num.
Display "Enter a possible prime number (0 to stop): " with no advancing.
Accept num.
If num = 0 stop run.
 
</lang>
 
Example:
<pre>
Enter a possible prime number (0 to stop): 2
2 is not prime.
Enter a possible prime number (0 to stop): 3
3 is prime.
Enter a possible prime number (0 to stop): 4
4 is not prime.
Enter a possible prime number (0 to stop): 5
5 is prime.
Enter a possible prime number (0 to stop): 65537
65537 is prime.
Enter a possible prime number (0 to stop): 0
</pre>
 
 
=={{header|CoffeeScript}}==