Answer to Question #6548 in C++ for karan shah
2012-02-14T07:53:19-05:00
write a program that does prime numbers test ... for result if number is prime it shows 1 and if number is not prime then result is 0.
1
2012-02-14T10:43:40-0500
#include <iostream> using namespace std; void main() { int A[99999]; int n; cout << "Enter the number: "; cin >> n; for(int i = 2; i <= n; i++) & A[i] = 1; for(int i = 2; i*i <= n; i++) { & if(A[i] == 1) & { & int j = i*i, k = 1; & while(j <= n) & { & if(A[j] == 1) & A[j] = 0; & j = i*i + k*i; & k++; & } & } } if(A[n] == 1) & cout << n << " - Is prime!"; else & cout << n << " - Is not prime!"; }
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