find the prime nmbr by using sieve of erathosthene


 

// find prime nmbr  1 to nmbr
// and prime factorisation of this nmbr
//by using sieve of erathosthene

#include<iostream>
#include<conio.h>
using namespace std;
void checkprime( int a[], int n,int k)
{int i,j;
     for(i=2;i<=n;i++)
    {     for(j=i*i;j<n;j=j+i)
       {  a[j]=1;   }  } 
 
    for(i=2;i<n;i++)
    {  if (a[i]==0){cout<<i<<" ";}}
   
    cout<<endl<<endl;
   cout<<" prime factorisation of nmbr ";
    for(i=2;i<k;i++)
{        if(a[i]==0)
    {    if(k%i==0)
      {cout<<i<<" ";}}
}
}

int main()
{ int i;
  int a[100]={0};
int k;
cout <<"prime nmbr between 1 to nmbr =";
cin>>k;

  checkprime(a,k,k);
    return 0;
}

Comments

Popular posts from this blog

Use of Recursion