Quantcast
Channel: Small Basic
Viewing all articles
Browse latest Browse all 669

Prime Number Factorization - Small Basic Featured Article

$
0
0

You can find this amazing article from Microsoft MVP here, on TechNet Wiki:

             Prime Number Factorization with Small Basic

 

In this article, Emiliano takes you through a simple method to factorize a number into its prime factors. It uses Small Basic, which can be downloaded at http://smallbasic.com/. Once installed, you'll be ready to go.

 

Check out the different sections of this article:

Table of Contents

 

 
 

Let's include one example of the code used. This is to...

Calculate primality

We've seen above that to check if a number is prime, we need to test its divisors up to the square root of the number itself. We must test each of those divisors, checking if the division give back no remainders. That can be done as follows:

' -- Test for primality of current divisor
isPrime = 1
Fori = 2 ToMath.SquareRoot(divisor)
  IfMath.Remainder(divisor, i) = 0 Then
    isPrime = 0
    Goto EndPrime
  EndIf
EndFor
EndPrime:

 

PNF on SmallBasic.com

The source code from this article is available for testing and download at: http://smallbasic.com/program/?LLS908          

 

Remember to head to the article for all the sections:

             Prime Number Factorization with Small Basic

 

And special thanks to Emiliano for this great addition to the Small Basic library of content!

   

Small and Basically yours,

   - Ninja Ed

 

See Also

 

 

 


Viewing all articles
Browse latest Browse all 669

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>