60 511
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #6548 in C++ for karan shah

Question #6548
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.
Expert's answer
#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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions