How to not use exponents?

Hi
I'm trying to make a program that find prime numbers, but when I get over 1000000 it start use exponents. How can I do that it only use plain numbers?
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>

using namespace std;

int main()
{
	double dele, tall, roun, svar;
	string text;

	tall = 5;
	dele = 2;
	svar = 0;
	roun = 0;
	text = "2 3";
	getchar();

	while (tall < 1200000 )
	{
		svar = tall/dele;
		roun = floor(svar);
		{
			if (dele > sqrt(tall))
			{
				dele = 2;
				std::string s;
				std::stringstream out;
				out << tall;
				s = out.str();
				text.append(" ");
				text.append(s);
				tall += 2;
//				cout<<"\n"<<s;
			}
			else
			if (svar == roun)
			{
				dele = 2;
				tall += 2;
			}
			else
			{
				dele += 1;
			}
		}
	}

    cout<<"Finish\n";

	ofstream file0;
    file0.open ("prim.txt");
    file0 << text;
    file0.close();
    cout<<"\nFinished writing to file.\n";
	getchar();
	return 0;
}
Using doubles for prime numbers is not accurate anyways; all primes are integers.

For this particular problem however, you will need a bignum library:
http://gmplib.org/
The above is an example, but there are a lot more bignum libraries.
closed account (3pj6b7Xj)
There is no need to specify the namespace in your std::string s; you already put using namespace std; at the start before main, remove the std:: and you'll see that your program still works the same way, just pointing that out to you to save you some typing. The same applies to stringstream but if you want to keep the std:: simply remove using namespace std; which is a lot better actually or you can specify only the namespaces you wish to use: using std::string and using std::stringstream ... using namespace std uses everything, even things you dont plan on using, possibly increasing the size of your program, I could be wrong about that tho.
Last edited on
Topic archived. No new replies allowed.