# Answer to Question #24701 in C++ for EMMANUEL

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"); &

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment