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!";

}

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!";

}

Learn more about our help with Assignments: C++

## Comments

## Leave a comment