Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. // ConsoleApplication3.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8. char* maxValueString;
  9. int maxValue;
  10. // Bugs so far: when providing argv as command line parameter, it doesn't get evaluated. Instead, the program keeps outputting the integers.
  11. int main(int argc, char** argv) //Starting point, provide optional variable input
  12. {
  13. if (argc <= 1)
  14. {
  15. do
  16. { //Variable test start
  17. cout << "Provide max positive integer? "; //Prompt
  18. cin >> maxValueString; // Variable input
  19. maxValue = atoi(maxValueString);
  20. } while (maxValueString <= 0);
  21. }
  22. else { maxValue = atoi(argv[1]); }
  23. for (int i = 2; i < maxValue; i++)
  24. {
  25. for (int j = 2; j*j <= i; j++)
  26. {
  27. if (i % j == 0)
  28. break;
  29. else if (j + 1 > sqrt(i)) {
  30. cout << i << "\n";
  31. }
  32. }
  33.  
  34. }
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement