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
damaskus [11]
3 years ago
11

Write a program that prompts the user to enter in a postive number. Only accept positive numbers - if the user supplies a negati

ve number or zero you should re-prompt them. Next, determine if the given number is a prime number. A prime number is a number that has no positive divisors other than 1 and itself. For example, 5 is prime because the only numbers that evenly divide into 5 are 1 and 5. 6, however, is not prime because 1, 2, 3 and 6 are all divisors of 6.
Computers and Technology
1 answer:
marusya05 [52]3 years ago
5 0

Answer:

The c++ program to check prime numbers is shown below.

#include <iostream>

using namespace std;

int main() {

   int num, prime=0;

   do

   {

       cout<<"Enter a positive number."<<endl;

       cin>>num;

       if(num<1)

       {

           cout<<"Invalid number. Enter a positive number"<<endl;

           cin>>num;

       }

   }while(num<1);

   

   if(num==1 || num==2 || num==3)

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

   else if(num%2 == 0)

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

   else

   {

       for(int k=3; k<num/2; k++)

       {

           if(num%k == 0)

               prime++;

       }    

   if(prime>1)

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

   else

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

   }

}

OUTPUT

Enter a positive number.

-7

Invalid number. Enter a positive number

0

Enter a positive number.

79

79 is a prime number.

Explanation:

The user input is validated for positivity. A do while loop along with an if statement is implemented for verification.

do

   {

       cout<<"Enter a positive number."<<endl;

       cin>>num;

       if(num<1)

       {

           cout<<"Invalid number. Enter a positive number"<<endl;

           cin>>num;

       }

   }while(num<1);

The test for prime number is done by using multiple if else statements.

If user inputs 1, 2, or 3, message is displayed.

Else If user inputs an even number, message is displayed for not prime. This is done by taking modulo of the number upon division by 2.

Else if user inputs neither an even number nor a number less than 3, the modulus of the number is taken with divisors beginning from 3 up to half of the input number.

For this, an integer variable prime is initialized to 0. A number can be completely divisible by itself or by its factors.

If the number is divisible by any of the divisors, value of variable prime is increased by 1. If value of prime is greater than 1, this means that the user input is divisible by more than one divisor. Hence, the given number is not a prime number.

You might be interested in
What food does swiss eat on christmas?
UkoKoshka [18]
The main Christmas meal is eaten on Christmas Eve and popular foods include a Christmas ham and scalloped potatoes with melted cheese and milk baked into it. Desert is often a walnut cake and Christmas cookies.
7 0
3 years ago
is a measurement that quantifies how much information can be transmitted over the network. A. Memory B. DMZ C. Bandwidth D. Clou
AnnZ [28]

Answer: Bandwidth....

6 0
3 years ago
For a project called "The Sheep Market", Aaron Koblin collected drawings of sheep from strangers on the Internet. He posted the
Furkat [3]

Answer:

Aaron could expect a diversity in the style of the sheep drawings.

Explanation:

Crowdsourcing is a simply a sourcing model in which an individual or organizations get goods and services, ideas and finances, from a large, relatively open and often rapidly growing group of internet users.

It makes it easier for participants to achieve a cumulative result through working differently on the same project. That is to say, it provides work between participants to achieve a cumulative result.

Its benefits is that, Crowdsourcing allows businesses to perform tasks more quickly than when a single employee is working alone. Again, Breaking up a project into a collection of smaller pieces and providing these pieces to a larger group of workers hastens the completion of projects. Overall, crowdsourcing presents a more efficient way to do work.

From the Question, Aaron was able to get different pictures of sheep in their numbers also because he used crowsourcing on amazon.

He got a variety of pictures and so many in such a short time for his project "The Sheep Market".

6 0
3 years ago
Which type of multiplexing divides transmission opportunities into slots of 125 microseconds with position inside each slot rese
Zinaida [17]

Answer: Time division multiplexing

Explanation: because a slot is equivalent to 125ms

And each position inside a slot is for each signal and a single bit frim each voice conversation is sent during each 125ms slot

7 0
3 years ago
To erase a character to the right of the insertion point, press the ____ key(s).
jeka94
<span><span>CTRL+HOME then delete, backspace, end.</span></span>
8 0
3 years ago
Other questions:
  • What was the first fully computer animated feature film?
    13·1 answer
  • Design a hierarchy c hart or flowchart for a program that calculates the current balance in a savin gs account. The program must
    8·1 answer
  • You have just purchased a motherboard that has an LGA 1156 socket for an Intel Pentium processor. What type of memory modules wi
    14·1 answer
  • Your textbook discussed a record store example where one user could perform a query to determine which recordings had a track le
    14·1 answer
  • Mississippi law codes state that bullying and cyberbullying are against the law. A court can decide to incur ___________________
    10·1 answer
  • Explain briefly why it is sometimes necessary to roll software back to a previous version, a procedure called "software
    9·1 answer
  • You are asked to write a program that prompts the user for the size of two integer arrays, user input for the size must not exce
    13·1 answer
  • LaShawn would like to post photos in a social media app, but the program needs to be modified in order to display a greater vari
    12·2 answers
  • What are some advantages to having ads tailored to your data?
    15·1 answer
  • What is the difference between
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!