This program takes a parameter, which is how many prime numbers you need. However if you want to make a program which checks whether a number is prime or not you can delete everything in the main function and put this line instead:

cout << isPrime (argv [1]) ? "It's a prime." : "It's not a prime."

Hope you find this useful, if it works correct ;).

128 Views
#include <iostream>
#include <stdlib.h>

using namespace std;

bool isPrime (float number)
{
	if (number == 1.0f) {
		return true;
	}
	for (float i=2.0f; i<number; i+=1.0f) {
		if (((number/i) - (int)(number/i)) == 0)
			return false;
	}
	return true;
}

int main (int argc, char** argv)
{
	cout << "Hello its me the prime number god!, I will give you " << argv [1] << " Prime Numbers like you requested.\n";
	int nums =0;
	while (nums != atoi (argv [1])){
		static int i =0;
		if (isPrime (i)){
			cout << "The number : " << nums << " is : " << i << endl;
			i++;
			nums++;
		}else
			i++;
	}
}

darkscript 5

Sorry everybody, I chose C syntax instead of C++.

Dani 1,954

Moved :)