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
if you put a drone on the charger at 8:12 and take a break at 10:03 how long is it on the charger. for
dalvyx [7]

Answer:

1 hour and 50 minutes

Explanation:

6 0
2 years ago
To put out a minor engine fire, use
Fynjy0 [20]

Shut off the engine. This will stop the flow of fuel, which can prevent a full-blown fire from occurring, step out of the car  use the fire extinguisher from a few feet away.

NOTE: If smoke or fire is coming from the rear of the car, DO NOT attempt to extinguish it. Immediately get as far away from the car as possible and call 911.

5 0
4 years ago
what will allow you to immediately exit the program without rebooting the computer, when you realize your browser is not respond
Vlada [557]

Answer:

the exit button on top right or x out of that certain tab

Explanation:

4 0
3 years ago
What is call by reference in function of c​
Vladimir [108]

Explanation:

The call by reference method of passing arguments to a function copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used to call. It means the changes made to the parameter affect the passed argument.

3 0
4 years ago
URGENT!!! If Pete selects the green square or little green camera icon on his camera dial, what mode is he selecting?
SOVA2 [1]

B Shutter Priority Mode

7 0
3 years ago
Other questions:
  • True/False
    11·1 answer
  • Why are video texts an example of multimedia? A. They use audio and visual elements together. B. They use one type of medium to
    13·2 answers
  • _____ is the unauthorized entry into a computer system via any means
    9·1 answer
  • You would like the user of a program to enter a customer’s last name. Write a statement thaUse the variables k, d, and s so that
    5·1 answer
  • List at least five smaller behaviours you could break the complex behaviour ""brushing my teeth"" into.
    6·1 answer
  • A ___________ variable is used to add up a set of values. fill in the blank
    8·1 answer
  • Please describe the role of games in modern society!
    5·2 answers
  • What stage of the development process is often called the pre-alpha phase and is the "meat" of the design process where features
    5·1 answer
  • The National Vulnerability Database (NVD) is responsible for actively performing vulnerability testing for every company's softw
    8·1 answer
  • A(n) _____ is any group of characters enclosed within either double or single quotation marks in javascript.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!