answersLogoWhite

0

#include<stdio.h>

#include<math.h>

bool is_prime (unsigned num) { if (num<2) // 0 and 1 are composite

return false;

if (!(num%2)) // 2 is the only even prime

return num==2;

const unsigned max_div = sqrt (num) + 1;

for (unsigned div=3; div<max_div; div+=2) {

if (!(num%div)) // the number is composite

return false;

}

// if we get this far, the number is prime

return true;

}

int main (void) {

unsigned num;

printf ("Enter a positive integer: ");

scanf ("%u", &num);

printf ("\n%u is %s\n", num, is_prime (num) ? "prime" : "composite");

return 0;

}

User Avatar

Wiki User

8y ago

What else can I help you with?

Related Questions

How can you identify any number whether prime or composite?

A prime number has only 2 factors which are 1 and itself. Composite numbers are everything else except 1 and 0. 1 and 0 are neither prime, nor composite.


How can you tell without any calculations whether a number ending in 5 is a prime or composites number?

If it is 5 it is a prime. If it is any other positive integer ending in 5 it is a composite.


Determine whether 24 is prime or composite?

It's composite


How do you identify a number if its prime or composite number?

To identify whether a number is prime or composite, look at its factors. A prime number has exactly two factors: one and itself. A composite number has more factors and can be written as the product of prime numbers. For example: Factors of 17: 1 and 17 so 17 is prime. Factors of 102: 1, 2, 3, 6, 17, 34, 51 and 102 so 102 is composite. It can be expressed as the product of prime numbers by prime factoring: 2 x 3 x 17


Is 294 a Prime or Composite number?

We must ascertain whether 294 contains factors other than 1 and itself in order to classify it as a prime or composite number. To start, we can see if it can be divided by any prime integer smaller than its square root, or roughly 17. As we examine the prime numbers that are smaller than 17: 294 ÷ 2 = 147 (a non-integer) 294 ÷ 3 = 98 (a non-integer) 58.8 (not a whole number) = 294 ÷ 5 42 (a whole number) = 294 ÷ 7 Thus, 294 divides by 7. Given that 294 divides evenly by 7, it has factors besides 1. 294 is a composite number as a result.


Is 8.5 an integer?

No, -8.5 is not an integer. An integer is a number without any fractions.


Write a program in vb to check whether a no is prime or not?

Function isPrime(ByVal n As Integer) As Boolean If n &lt; 2 Then Return False End If Dim sqrtn As Integer = Math.Sqrt(n) + 1 For i As Integer = 2 To sqrtn If (n Mod i) = 0 Then Return False End If Next Return True End Function


How do you prove that a number is a composite?

To prove whether a number is composite, factor it. A number having any factor besides 1 and itself is composite.


Write a program to check whether the number is divisible by 3 or not by using the?

I assume you mean is an if the number is an integer multiple of 3i am unfamiliar with C but the theory would be,find if a is integer multiple of 3b=a/3b==round(b).if 1 "yes"else "no"this is an inefficiency way but will get the job done


Write a program that prompts the user to input a positive integer It should then output a message indicating whether the number is aprime or not?

Output a prompt.Either:Read from standard input (std::cin) to an integer.Or:Read a line from standard input (std::getline()) to a string.Create a string stream (std::stringstream) to read the string.Read from the string stream to an integer.For each integer from 2 to half the entered integer:If the entered integer is divisible by the current integer:The number is not prime.Exit the program.The number is prime.Exit the program.


Describe whether 35 a composite neither or prime?

35 is a composite number because it has more than two factors


What is the integer of 6.51 plus 1.35 plus 15.46?

Do the addition, then convert to an integer. The result will depend on whether you want to round to the nearest integer, round up, or round down.