Answer to Question #56474 in C++ for Nithya
2015-11-19T12:52:01-05:00
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.
1
2015-11-23T04:14:34-0500
Solution #include <iostream> #include <math.h> #define N 10 using namespace std; bool isPrime(int k) { int i; for(i=2;i*i<=k;i++) if(k%i==0) return false; return true; } int main(int argc, char **argv) { int n; cout<<"Input number: "; cin>>n; cout<<"Prime numbers: \n"; int k; for(k=1;k<=n;k++) if(isPrime(k)) cout<<k<<endl; 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 !
Learn more about our help with Assignments:
C++
Comments
Leave a comment