Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A prime number is a number that is only evenly divisible by itself and 1. For ex

ID: 3539723 • Letter: A

Question

A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be easily divided by 1, 2, 3, and 6.

Design a Boolean function named isPrime, which takes an integer as an arugument and returns True if the argument is a prime number, or False otherwise. Use the function in a program that prompts the user to enter a number and then displays amessage indicating whether the number is prime.

Explanation / Answer

bool isPrime(int number)

{

int i,factorscount=0;

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

{

    if(number%i==0)

      {

          factorscount++;

      }

if(factorscount==1)

{

return true;

}

else

{

return false;

}

}


main()

{

promt("Enter the number to check : ");

bool answer=isPrime(number);

if(answer=="True)

Promt("True");

else

Promt("False");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote