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.
1
Expert's answer
2012-09-28T12:02:56-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS