Breaking the program!

Hello,

I need to find the largest positive integer, that I can get from this program. That means this program should break when it displays the largest positive prime number. How can I do it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<cmath>
using namespace std;

bool isPrime(int n)
{

	for (int i = 2; i <sqrt(n + 1); i++)
		if (n % i == 0)
		{
			return false;
		}
	return true;
}

int main()
{
	{
		int i = 2;
		while (i>0)
		{
			int newNum = (pow(i, 2) + 1);
			if (isPrime(newNum) == true)
				cout << newNum << endl;
			i++;
		}
		
	}
	system("pause");
	return 0;
}
What you are asking seems very trivial. Why not just enter a very large prime into the program and see if it breaks? Why do you need someone to tell you that?

Note that the largest value that an int can hold is 231 - 1
http://www.cplusplus.com/doc/tutorial/variables/
start at MAX_INT and work your way back?

Edit: or perhaps UINT_MAX?
Last edited on
Topic archived. No new replies allowed.