answersLogoWhite

0


Best Answer

#include<iostream>

bool is_composite (const size_t);

bool is_prime (const size_t);

int main()

{

for (size_t num=1; num<=10; ++num)

if (is_composite (num))

std::cout << num << " is composite\n";

}

bool is_composite (const size_t num)

{

if (num < 4U)

return false;

return !is_prime (num);

}

bool is_prime (const size_t num)

{

const size_t two = 2U;

if (num < two)

return false;

if (!(num % two))

return num == two;

const size_t max = static_cast<size_t>(sqrt (static_cast<double>(num)));

for (size_t div = 3U; div <= max; div += two)

if (!(num % div))

return false;

return true;

}

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Composite numbers from 1-10 in c plus plus programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the composite numbers of 110?

10, 22, 55, 110 are the composite factors of 110.


Is 110 plus 120 a composite number?

110 + 120 = 330 330 is a composite number.


Is 110 prime or composite?

110 is composite. A prime number is a number that is divisible only by 1 and itself; it has no other factors. A composite number is a number that is divisible by more than 2 numbers. The factors of 110 are 1, 2, 5, 10, 11, 22, 55, and 110. Therefore, 110 is a composite number.


What are all the composite numbers 100 to 110?

100, 102, 104, 105, 106, 108, 110


Is 110 is it prime or composite?

110 is a composite number. 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.


Is 110 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. 110 is composite.


What is the composite numbers from 100 to 110?

102 104 105 106 108


Is 110 prime composite or neither?

110 is a composite number. A prime number has only 2 factors which are 1 and itself. Composite numbers are everything else except 1, 2, and 0. 1, 2, and 0 have a different name.


What are the composite numbers from 100 to 120?

The numbers 100, 102, 104, 105, 106, 108, 110, 111, 112, 114, 115, 116, 117, 118, 119 and 120 are composite (including the boundaries).


What are the composite numbers from 90 to 110?

90, 91, 92, 93, 94, 95, 96, 98, 99, 100, 102, 104, 105, 106, 108, 110


What is the composite factor of 110?

10, 22, 55, 110


What are the composite numbers between 106 and 120?

108, 110, 111, 112, 114, 115, 116, 117, 118, 119.