Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- int counter = 0;
- int j = 3;
- int input;
- bool registered;
- ofstream primeOutput;
- primeOutput.open("output.txt");
- cout << "Enter A Number and I will find all the prime number from 1 - X: ";
- cin >> input;
- if (input >= 2)
- {
- primeOutput << 2 << "\n";
- counter++;
- }
- for (int i = 1; i <= (input); i = i + 2)
- {
- registered = false;
- for (int j = 1; j < 10; j++)
- {
- if ((i % j == 0) && (i != j) && (j != 1) && !registered || (i == 1))
- {
- registered = true;
- }
- else if (!registered && (j == 9))
- {
- primeOutput << i << "\n";
- counter++;
- }
- }
- }
- cout << "Solutions can be found in this file's directory named \"output.txt\"" << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement