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; }
Comments
Leave a comment