Advertisement
thesonpb

sàng eratosthenes

Mar 30th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. void deleteArray(int a[], int& n, int pos){
  4.     for(int i=pos; i<n-1; i++){
  5.         a[i]=a[i+1];
  6.     }
  7.     n--;
  8. }
  9. int main(){
  10.     int n;
  11.     cin >> n;
  12.     int a[1000];
  13.     for(int i=0; i<=n-2; i++){
  14.         a[i]=i+2;
  15.     }
  16.    
  17.     do{
  18.         cout<<a[0]<<" ";
  19.         for(int i=1; i<n; i++){
  20.             if(a[i]%a[0]==0) deleteArray(a, n, i);
  21.         }
  22.         deleteArray(a, n, 0);
  23.        
  24.     }
  25.     while(n!=0);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement