63 040
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #56422 in C++ for raneem

Question #56422
Write a program that asks the user to enter a positive number then displays all numbers
less or equal to it that are prime each one a separate line.
Expert's answer
#include <iostream>
#include <math.h>
using namespace std;
int main (){
int n = 0;
int divisor =2;
cout<<"Please input a positive number n = ";
cin>>n;
for( int i=3;i<=n;i++){
for ( int j = divisor;j<=(round(0.5*i)+1);j++){
if ((i%j)==0) break;
if (j==round(0.5*i)+1) cout<<i<<endl;
}
}
cout<<"Program Finished";
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions