A program to display Nth Prime number

Hi guys am new in the forum. I need help in compiling a program that gives the next prime number example if someone says 5 then the program will give the next prime number 7

This is what i have so far, but is not successful. I will appreciate any help. Thanks in advance


using namespace std;

int isPrime( int, int, int, int, int, int);
int num, b, c, d, x, y;

int main()

cout << "Enter an integer = ";
cin >> num;
isPrime (num, b,c,d,x,y);
cout << "The factors are " << endl;

for(int y=1, d=0; y<=abs(num); y++)

cout << y << " and " << b << endl;
cout << -y << " and " << -b << endl;

cout << num << " is a prime number." << endl;
cout << num << " is not a prime number." << endl;

return 0;

int isPrime(int num,int b, int c, int d, int x, int y)

for(int i= num; i >= y ; i++)
cout << "The N-th prime number is : " << endl;
return 0;

Last edited on
First of all format your code using the <> button so it's easier to read.

I'll lay out the general idea. Start at the input number + 2 (assuming the input number will always be prime, not sure from your description). Call a function called is_prime() that determines if the number is prime or not. If not, increment the input number by one and repeat the loop.

is_prime() will work like this. Set i = 2. While i * i < input, check if (input % i) ==0. If it does, then return false. If it doesn't then return true.
Topic archived. No new replies allowed.