Git Product home page Git Product logo

brianklemm-git / prime-number-generator Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 154 KB

This is a C++ prime number generator. It generates prime numbers by user specified count. It then saves the found prime numbers to a .dat file. If a user later request a lesser number of prime numbers the program will provide them from the file instead of calculating them again. The program never calculates a prime twice.

C++ 93.66% CMake 6.34%

prime-number-generator's Introduction

Prime Number Generator

This is a C++ prime number generator. It generates prime numbers by user specified count. It then saves the found prime numbers to a .dat file. If a user later request a lesser number of prime numbers the program will provide them from the file instead of calculating them again. The program never calculates a prime twice.

isPrime(int n) determines if a number is prime.

Progam Starts:

  • Current number of saved primes are announced in the console
  • The user is prompted for how many primes they want listed
  • If no primes.dat exists in the program directory a primes.dat file is created
  • Requested number of primes is compared to the saved number of primes in primes.dat

User request less than the number of stored primes

  • If the requested is less than or equal to the number of primes saved in primes.dat the primes requested are read from primes.dat and no new calculations are preformed.
  • Program then closes

User request more than the number of stored primes

  • Only the additional requested primes are calculated
  • The obvious cases of negative numbers, 0, 1, and all even numbers greater than 2 are eliminated.
  • Modulo the test case with all odd numbers upto the square root of the test case until a 0 remainder is found or the square root of the test case is exceeded.
  • true is returned if the number is prime and false is returned if the number is not prime
  • If true is returned the test case is added to the vector primesFound
  • In both cases of a true or false return, the function continues to the next test case until the primesFound vector contains the requested number of primes.
  • Once the primesFound contains the number of user requested primes the vector primesFound is saved to the primes.dat file.

prime-number-generator's People

Contributors

brianklemm-git avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.