Project Euler Problem 7 Solution – 10001st Prime

10001st Prime is another prime calculating problem… nothing hard. my solution is below and written in C++.

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int isPrime(int number){
int count=0;
for(int a = 1; a<=number ;a++)
{
if(number % a == 0)
count++;
}
if(count == 2)
return number;
return 0;
}

int main(){
int primecount = 0;
int num = 1;
int prime = 0;
bool working = true;
while(primecount != 10001){
prime = isPrime(num);
num++;
if(prime > 0){
primecount++;
}
}

cout << prime <<"n";
std::cout << "Press ENTER to continue...";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), 'n' );
return 0;
}

 
									

Leave a Reply

Your email address will not be published. Required fields are marked *