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
adoni [48]
3 years ago
8

Write a program to determine if a positive integer,N, is prime.

Computers and Technology
1 answer:
Olin [163]3 years ago
8 0

Answer:

// program in C++.

#include <iostream>

using namespace std;

// main function

int main()

{

   // variables

 int N;

 bool flag = true;

 cout << "Enter a positive number: ";

 // read number

 cin >> N;

 // check number is positive or not

 while(N<0)

 {

     cout<<"Number is not positive!! Enter again:";

     // read again if input is negative

     cin>>N;

 }

 // check prime or not

 for(int a = 2; a <= N / 2; a++)

 {

     if(N % a == 0)

     {

         flag = false;

         break;

     }

 }

 // if flag is true then prime

 if (flag)

     cout << "Input number is prime.";

 else

     cout << "Input number is not prime.";

 return 0;

}

Explanation:

Read a number from user and assign it to variable "N".Check number is positive  or not.If input is negative then ask again to enter a positive number until user enters a positive number.If input is divisible by any number from  2 to n/2 set flag equal to "false".After the loop, if flag is "true" then print number is prime else number is not prime.

Output:

Enter a positive number: -12                                                                                              

Number is not positive!! Enter again:-5                                                                                    

Number is not positive!! Enter again:23                                                                                    

Input number is prime.

You might be interested in
Help me with the question please..​
PIT_PIT [208]

First addition, then division

4 0
3 years ago
The name for the instructions you write to a computer in a program
aliina [53]

Answer:

Code

Explanation:

The code is instructions that you can write yourself or download from online

4 0
2 years ago
Read 2 more answers
Define storage device with two examples? ​
Vlad [161]

Answer:

Hehe!

Explanation:

Storage Device is a technology consisting of computer components and recording media that are used to retain digital data. It is a core function and fundamental component of computers. The central processing unit of a computer is what manipulates data by performing computations.

Examples: Hard disk and Floopy Disk.

7 0
2 years ago
Read 2 more answers
How do you go about placing a picture in your question?
rodikova [14]

when you are asking your question you can click on the link down at the bottom and when it pops up all your files click the one who want to send

plz mark brainliest lol seemed like an easy question but i need them to rank up so yea lol

6 0
3 years ago
Read 2 more answers
Now, my Laptop has been working since I bought it yesterday it won’t start up and it when it does it overheats and shuts off, th
tekilochka [14]

I would bring it back since it’s not working. No way would I spend hard earned money on something that doesn’t work.

Hope this helps.

7 0
3 years ago
Read 2 more answers
Other questions:
  • Upgrading only the motherboard will give some performance improvement to a computer system. Why would the improvement be limited
    14·1 answer
  • All web page urls begin with the letters ____.
    6·1 answer
  • Please help. 15 points!!!!
    8·2 answers
  • Which of these is an aggregator?
    9·2 answers
  • . Write a toString method for this class. The method should return a string containing the base, height and area of the triangle
    10·1 answer
  • Which term describes the distance from one point on a wave to the same point on the next wave?
    13·2 answers
  • Rate my dog out of ten give explanation why
    12·1 answer
  • What can hack or code can I use to get a shadow or frost dragon in adopt me
    6·2 answers
  • Please Help ASAP. Marking Brainliest For Correct Answer.
    5·1 answer
  • This question involves the creation and use of a spinner to generate random numbers in a game. a gamespinner object represents a
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!