Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main() {
- int isProst = 1;
- int count, countMax;
- count = 2;
- int arr[1000] = {1,2};
- cout << "Enter the amount of numbers: " << endl;
- cin >> countMax;
- for (int a = 3;count<countMax;a+=2)
- {
- isProst = 1;
- for (int i = 3; i < sqrt((double)a) + 1; i+=2)
- {
- if (a%i == 0)
- {
- isProst = 0;
- break;
- }
- }
- if (isProst)
- {
- arr[count] = a;
- count++;
- }
- }
- for (int i =0; i < count; i++)
- cout<<arr[i]<<endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment