Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication3.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- char* maxValueString;
- int maxValue;
- // Bugs so far: when providing argv as command line parameter, it doesn't get evaluated. Instead, the program keeps outputting the integers.
- int main(int argc, char** argv) //Starting point, provide optional variable input
- {
- if (argc <= 1)
- {
- do
- { //Variable test start
- cout << "Provide max positive integer? "; //Prompt
- cin >> maxValueString; // Variable input
- maxValue = atoi(maxValueString);
- } while (maxValueString <= 0);
- }
- else { maxValue = atoi(argv[1]); }
- for (int i = 2; i < maxValue; i++)
- {
- for (int j = 2; j*j <= i; j++)
- {
- if (i % j == 0)
- break;
- else if (j + 1 > sqrt(i)) {
- cout << i << "\n";
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement