# Answer to Question #15584 in C++ for amna

Question #15584

prime numbers are those numbers which are only divisible with 1 and number itself. you are required to write a program (using while loop or do while or if statement )that generate the prime numbers between the range defined by user.

Expert's answer

#include "stdafx.h"

#include <iostream>

using namespace

std;

int _tmain(int argc, _TCHAR* argv[])

{

int n=0;

int

m=0;

while(true){

cout<<"Please enter n:

"<<endl;

cin>>n;

bool prime=true;;

for (int i=1; i<n;

i++){

for (int j=2; j<i; j++){

if

(i%j==0&&i!=1){

prime=false;

break;

}

}

if

(prime==true){

cout<<i<<endl;

}

prime=true;

}

}

return

0;

}

#include <iostream>

using namespace

std;

int _tmain(int argc, _TCHAR* argv[])

{

int n=0;

int

m=0;

while(true){

cout<<"Please enter n:

"<<endl;

cin>>n;

bool prime=true;;

for (int i=1; i<n;

i++){

for (int j=2; j<i; j++){

if

(i%j==0&&i!=1){

prime=false;

break;

}

}

if

(prime==true){

cout<<i<<endl;

}

prime=true;

}

}

return

0;

}

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