1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Grace [21]
3 years ago
6

Write a program that declares an array of size 1,230 and stores the first 1,230 prime numbers in this array. The program then us

es the first 1,230 prime numbers to determine if a number between 2 and 100,000,000 is prime. If a number is not prime, then output at least one of its prime factors.
Computers and Technology
1 answer:
timurjin [86]3 years ago
3 0

Answer:

The complete question is :

A positive integer n is called prime if n > 1 and the only factors of n are 1 and n. It is known that the positive integer n>1 is prime if n is not divisible by any prime integer m≤n. The 1230th prime number is 10,007. Let t be an integer such that 2≤t≤100,000,000. Then t is prime if either t is equal to one of the first 1230 prime numbers or t is not divisible by any of the first 1230 prime numbers. Write a program that declares an array of size 1,230 and stores the first 1,230 prime numbers in this array. The program then uses the first 1,230 prime numbers to determine if a number between 2 and 100,000,000 is prime. If a number is not prime, then output at least one of its prime factors.

Explanation:

The program is :

#include<iostream>  

#include<cmath>  

using namespace std;  

const int SIZE = 1230;  

bool isPrime(int number);  

void first1230PrimeNum(int list[], int length);  

void primeTest(int num, int list[], int length);

int main()  

{

   int primeList[SIZE];

   int number;

    first1230PrimeNum(primeList, SIZE);

    cout<<"Enter an integer between 2 and 100,000,000: ";

    cin>>number;

    cout<<endl;

    primeTest(number, primeList, SIZE);

    system("pause");

     return 0;

}  

bool isPrime(int number)  

{

 int i; //to iterate

  //loop till sqrt(number)

    for(i=2; i<=sqrt(number); i++)

      {

         //if any factor

         if(number%i == 0)

          return false;//return false

     }

        return true; //otherwise return true

}  

void first1230PrimeNum(int list[], int length)  

{

 int i=0, number = 2; //i to itrate and number to test prime

 while(i<length) //get 1230 primes

   {

    if(isPrime(number)) //check if prime or not

    {

      list[i] = number; //add it to list

      i++; //increment i

    }

 number++; //increment number

  }  

}  

void primeTest(int num, int list[], int length)  

{

int i; //i to iterate

 //loop through list

 for(i=0; i<length; i++)

{

//if num is in list then it is prime

  if(num == list[i])

 {

  cout<<num<<" is a prime"<<endl;

   return;

   }

   //if divisible by any number then not a prime

    if(num % list[i] == 0)

{

  cout<<num<<" is not a prime"<<endl;

   cout<<"One of the prime factor: "<<list[i]<<endl;

   return;

 }

}

cout<<num<<" is a prime"<<endl;  

}

OUTPUT :

Enter an integer between 2 and 100,000,000 : 104659

104659 is a prime.

You might be interested in
Which behaviors might lead someone to have a low credit score?
Dovator [93]
Spending more than you have and not paying it back on your bill.

7 0
3 years ago
Read 2 more answers
What is true concerning physical and logical topologies? Physical topologies are concerned with how a network transfers frames.
Sindrei [870]

Answer:

Physical means the actual wires.  Physical is concerned with how the wires are connected. Logical is concerned with how they transmit.

Explanation:

8 0
3 years ago
.When might you want to use static IP addressing?
nikitadnepr [17]

Answer:

You might use static ip addressing when your network will be small and you don´t have plans to create a bigger network from this.

Explanation:

When you use static ip addressing you have to configure the routes between hosts manually, is easy to define this rules manually when your network is small because you know all the addresses and the routes to configure. But if your network is bigger and you didn´t know all the host addresses will take a long time to configure this manually.

4 0
3 years ago
An assignment notebook is important because that is where students
lesya [120]
I think it would be D

8 0
3 years ago
Read 2 more answers
In what ways is a mouse more efficient than a keyboard?
d1i1m1o1n [39]
It sometimes takes less effort to move the mouse than to press keys in the keyboard.

But the keyboard is often more efficient than the mouse. Keyboard shortcuts can be used to get tasks done in an instant, way faster than a mouse. Repetitive actions are also much easier.
5 0
4 years ago
Read 2 more answers
Other questions:
  • Suppose that, in addition to edge capacities, a flow network has vertex capacities. That is each vertex vv has a limit l(v)l(v)
    7·1 answer
  • What is the correct order of operations for protecting a critical section using a binary semaphore?
    15·1 answer
  • Darren wants to substitute every occurence of the word bulky in his spreadsheet with the word strong. which of these options sho
    11·1 answer
  • Which part of an I-statement involves a description of your needs or feelings? The part of an I-statement involves a description
    5·2 answers
  • What would you have to know about the pivot columns in an augmented matrix in order to know that the linear system is consistent
    13·1 answer
  • Why is a partial mesh topology more common than a full mesh topology?
    5·2 answers
  • In which drawer can you set certain lights to light up on your micro:bit?
    12·2 answers
  • What are two advantages of a pay-for-use online conferencing service compared to a free service? (Choose two)
    5·1 answer
  • #Step 1 Get first value from user #Remove the hastag (#) from the front of ONE of the #three lines below, which will allow the p
    9·1 answer
  • The term for an operator that may not evaluate one of its subexpressions is
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!