I made a command line program in C/C++ that outputs a list of prime numbers.
I only compiled on Linux, so there may be some problems on Windows, if there's problem on Windows, create a new Visual Studio project with the following source code:
Code:
//Prime number calculator
//This program lists all prime numbers lower than certain value.
// Created on September 23, 2008, 10:18 PM
#include <stdlib.h>
#include <iostream>
//check for prime number
bool isPrime(int integer)
{
//loop to mod with any numbers lower than integer-1 and higher than 1
for (int i = 2; i < integer; i++)
{
//skip and return false if 0 was returned.
if (integer % i == 0)
{
return false;
break;
}
}
//if 0 was not returned, this is a prime number.
return (true);
}
int main(int argc, char** argv)
{
//preparations
std::cout << "Prime Number Generator 1.0\nThis program outputs all prime numbers lower than certain value. If you entered invalid value, the program may be buggy. \nEnter 0 or 1 to exit.";
//----------
restart:
std:: cout << "Enter the max. limit: \n>";
//long double is the biggest possible data type
long double limit;
//input the limit
std::cin >> limit;
std::cout << "\n";
//if 0 and 1 was entered, exit.
if (limit <= 1)
{
std::cout << "Exit.\n";
return (EXIT_SUCCESS);
}
//main loop
//the counter increase 2 every time for performance.
for (int current = 3; current < limit; current += 2)
{
//keep checking the current value
//if it is prime, output the value
if (isPrime(current))
{
std::cout << current << "\n";
}
}
goto restart; //go back
//exit in case of bugs
return (EXIT_FAILURE);
}
and see attachment for the compiled executable
Now I tried to enter 99999999999999999999999999 and find what's the limit of the program