Question #24701

write a function which outputs all prime numbers between 2 and a given positive integer n;

void primes(unsigned int n);

void primes(unsigned int n);

Expert's answer

#include<string>

#include<iostream>

using namespace std;

void primes( int n){

int k=0;

& for( int i=2;i<n;i++){

for( int t=2;t<i;t++)& {

if(i%t==0)

k++;

}

& if(k==0)

& cout<<i<<endl;

& k=0;

&

}& &

& }

int main (){

int n;

cout<<"enter n : ";

cin>>n;

primes( n); &

&

system("PAUSE"); &

}

#include<iostream>

using namespace std;

void primes( int n){

int k=0;

& for( int i=2;i<n;i++){

for( int t=2;t<i;t++)& {

if(i%t==0)

k++;

}

& if(k==0)

& cout<<i<<endl;

& k=0;

&

}& &

& }

int main (){

int n;

cout<<"enter n : ";

cin>>n;

primes( n); &

&

system("PAUSE"); &

}

## Comments

## Leave a comment