primes from 1 to n c 2b 2b

Solutions on MaxInterview for primes from 1 to n c 2b 2b by the best coders in the world

showing results for - "primes from 1 to n c 2b 2b"
Andrea
29 Jan 2019
1#include<iostream>
2 
3using namespace std;
4   
5int main(){
6   
7    int N, i, j, isPrime, n;
8 
9    cout << "Enter the value of N\n";
10    cin >> N;
11   
12    // For every number between 2 to N, check 
13    // whether it is prime number or not 
14      
15    for(i = 2; i <= N; i++){
16        isPrime = 0;
17        // Check whether i is prime or not
18        for(j = 2; j <= i/2; j++){
19             // Check If any number between 2 to i/2 divides I 
20             // completely If yes the i cannot be prime number
21             if(i % j == 0){
22                 isPrime = 1;
23                 break;
24             }
25        }
26           
27        if(isPrime==0 && N!= 1)
28            cout << i << " ";
29    }
30 
31   return 0;
32}
33