Guest User

Untitled

a guest
May 2nd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <math.h>
  5. using namespace std;
  6. int main() {
  7. int isProst = 1;
  8. int count, countMax;
  9. count = 2;
  10. int arr[1000] = {1,2};
  11. cout << "Enter the amount of numbers: " << endl;
  12. cin >> countMax;
  13. for (int a = 3;count<countMax;a+=2)
  14. {
  15. isProst = 1;
  16. for (int i = 3; i < sqrt((double)a) + 1; i+=2)
  17. {
  18. if (a%i == 0)
  19. {
  20. isProst = 0;
  21. break;
  22. }
  23. }
  24. if (isProst)
  25. {
  26. arr[count] = a;
  27. count++;
  28. }
  29.  
  30. }
  31. for (int i =0; i < count; i++)
  32. cout<<arr[i]<<endl;
  33. system("pause");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment