Results 1 to 5 of 5

Math Help - Simple Windows application to compute prime numbers

  1. #1
    Newbie
    Joined
    Jul 2010
    Posts
    2

    Simple Windows application to compute prime numbers

    I know this program isn't groundbreaking but after looking at simple prime number calculators online I decided to create my own. On my machine I was able to enter numbers as high as 18 or 19 digits (although you don't want a very large range!). My website is completely unknown so I was just hoping for some feedback on this, and possibly making it known to anyone who may find it handy.

    It runs on Windows and requires .NET framework 2.0 or greater. As long as you have an updated version of Windows it should work

    Simple Windows application to compute prime numbers-prime_preview_01.png

    Download directly
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor Also sprach Zarathustra's Avatar
    Joined
    Dec 2009
    From
    Russia
    Posts
    1,506
    Thanks
    1
    The program in JAVA:

    [PHP]import java.util.Scanner;
    public class Primes {
    public static void main (String[]args){
    Scanner input=new Scanner(System.in);

    System.out.print("Enter two numbers");
    int num1=input.nextInt();
    int num2=input.nextInt();
    Boolean isPrime=true;
    for(int i=num1; i<num2; i++){
    for(int j=2; j<=(int)Math.sqrt(i) && isPrime; j++){
    if(i%j==0)
    isPrime=false;}
    if(isPrime==true)
    System.out.print(i);
    isPrime=true;
    }
    }
    }

    [/PHP]
    Follow Math Help Forum on Facebook and Google+

  3. #3
    MHF Contributor undefined's Avatar
    Joined
    Mar 2010
    From
    Chicago
    Posts
    2,340
    Awards
    1
    I think it's cool, thanks for sharing. For people interested in the underlying algorithm, this is commonly known as a segmented sieve. To the OP: You might have fun programming a segmented Euler phi sieve (using a prime sieve to get values of Euler phi for some larger integers)...

    @Also sprach Zarathustra: That's trial division and generally much slower, except for certain inputs.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor Also sprach Zarathustra's Avatar
    Joined
    Dec 2009
    From
    Russia
    Posts
    1,506
    Thanks
    1
    Yes, I know... (just for fun...)
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Jul 2010
    Posts
    2
    Quote Originally Posted by Also sprach Zarathustra View Post
    The program in JAVA:
    Cool. I actually first wrote this in Java but converted it to Visual Basic as a means to help me start learning it. I also added a feature which calculates the range in 5000 number increments to avoid very large arrays being addressed in memory.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 1
    Last Post: October 22nd 2011, 01:37 PM
  2. Compute f'(x) and finding critical numbers
    Posted in the Calculus Forum
    Replies: 2
    Last Post: November 19th 2010, 08:53 AM
  3. Replies: 45
    Last Post: June 6th 2010, 07:18 PM
  4. Replies: 1
    Last Post: June 3rd 2010, 10:39 AM
  5. Replies: 3
    Last Post: September 15th 2007, 04:49 PM

Search Tags


/mathhelpforum @mathhelpforum