Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cfsetting requesttimeout="500">
- <form action="isprime.cfm" method="post">
- Find Primes out to <input type="text" name="myNum" value="">
- <input type="submit" value="Find Primes">
- </form>
- <cfif structKeyExists(form,"myNum")>
- <table>
- <tr>
- <td colspan="10">
- Finding Prime Numbers from 1 to <cfoutput>#form.myNum#</cfoutput>
- </td>
- </tr>
- <br>
- <cfset count = 0>
- <tr>
- <cfloop index="p" from="1" to="#myNum#" step="1">
- <cfif isPrime(p)>
- <td><cfoutput>#p# </cfoutput></td>
- <cfset count = count + 1>
- <cfif count mod 10 eq 0>
- </tr><tr>
- </cfif>
- </cfif>
- </cfloop>
- </table>
- </cfif>
- <cfscript>
- public boolean function isPrime(required numeric myNum ) {
- if (myNum < 2) {return false;}
- if (myNum == 2) {return true;}
- if (myNum % 2 == 0) {return false;}
- for ( i = 2; i * i <= myNum; i++){
- if (myNum % i == 0) return false;
- }
- return true;
- }
- </cfscript>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement