Implementation of finding the Prime Numbers upto a given number N .

Правка en3, от vicky1997, 2016-09-14 17:50:04

  • Hi all !!! *

  • Finding Prime Numbers In A Different Way... *


include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

int isprime(ll n)

{

if(n<=3)

    return 1;

if(n%2==0||n%3==0)

    return 0;

for(ll i=5;i*i<=n;i+=6)

{

    if(n%i==0||n%(i+2)==0)

        return 0;

}

return 1;

}

int main()

{

//ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

ll N,i;

cout<<"\nEnter the Number N :";cin>>N;

cout<<"\nPrime Numbers <="<<N<<" are : \n";

for(i=2;i<=N;i++)

{

    if(isprime(i))

            {

        cout<<i<<",";

    }

}

return 0;

}


  • If found any corrections please comments... *

  • Help Appreciated... *


Теги prime numbers, implementation

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский vicky1997 2016-09-14 17:50:04 88
en2 Английский vicky1997 2016-09-14 17:47:27 0 Tiny change: 'tdc++.h>\nusing na' -> 'tdc++.h>\n\nusing na'
en1 Английский vicky1997 2016-09-14 17:45:28 1253 Initial revision (published)