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
4vir4ik [10]
4 years ago
5

Write a program that tests whether an integer is a prime number.

Chemistry
1 answer:
Alika [10]4 years ago
4 0

Answer:

#include <iostream>

using namespace std;

int main() {

   int n;

   cin>>n;//taking input form the user.

   bool b=true;

   for(int i=2;i<n;i++)//looping

   {

       if(n%i==0)//checking that i divides n.

       {

           cout<<"The number is not prime";

           b=0;

           break;

       }

   }

   if(b)

   {

       cout<<"The number is prime";

   }

return 0;

}

Input:-

23

Output:-

The number is prime.

Explanation:

The above written program is in C++.First I have declared an integer n.Then taking input form the user and storing it in n abd also declared a boolean variable with value true.Then I have used a for loop for checking n is divisible by any number from 2 to n-1 if it is then printing the message of not prime,making the value of b to false and coming out of the loop.out of the loop if the value of the b is true then printing the number is prime.

You might be interested in
Why do we use acid during the detection of halogens​
ohaa [14]

Answer:

Nitric acid decomposes sodium cyanide and sodium halide. else, they precipitate in test and misguide the result. Therefore, dilute nitric acid is added before testing halogens to expel all the gases if evolved.

8 0
2 years ago
1. If a person's mass is 56 kg, what is this weight in pounds?<br> 56kg
Natali [406]

Answer:

123lb

Explanation:

lb= 2.2046 kg

56×2.2046= 123lb

3 0
3 years ago
How are gold medal cells and human cells alike and different
kondor19780726 [428]
Your skin is a tougher substance

3 0
3 years ago
Which is the process by which atoms are joined to form compounds? A. photosynthesis B. metamorphosis C. physical bonding D. chem
lina2011 [118]

The answer to your question would be D) chemical bonding because when you are bonding atoms to each other you are creating a new and unique substance

5 0
3 years ago
Read 2 more answers
Which is true about equilibrium
Mashcka [7]
The concentration of reactants is always equal to the concentration of products
5 0
4 years ago
Other questions:
  • What must happen for heat to be transferred by convection?
    14·1 answer
  • Which statement best describes the nature of science
    5·2 answers
  • Consider the following reaction, equilibrium concentrations, and equilibrium constant at a particular temperature. Determine the
    8·1 answer
  • Which planet do scientists believe prevented the asteroids in the asteroids belt from forming a planet?
    11·2 answers
  • Help me fill out this table please! We haven’t gotten any information aside from this and the teacher expects us to understand i
    9·1 answer
  • The group in an experiment that is not exposed to the tested variable is called the group
    9·1 answer
  • You used a variety of media with a NaCl concentration ranging from 0.5% to 15%. Which of these media would have the lowest water
    5·1 answer
  • Question 10
    5·1 answer
  • Ionic bonds form between which two types of elements?​
    10·2 answers
  • Differentiate between electrolytic and metallic conductors.<br><img src="https://tex.z-dn.net/?f=%20%5C%5C%20" id="TexFormula1"
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!