answersLogoWhite

0

#include<iosys.h>

#include<math.h> // for sqrt()

bool is_prime (unsigned num) {

if (num<2) return false; // 2 is the first prime

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

// largest potential factor is square root of num

unsigned max = (unsigned) sqrt ((double) num) + 1;

// test all odd factors

for (unsigned factor=3; factor<max; factor+=2) if (!(num%factor)) return false;

return true; // if we get this far, num has no factors and is therefore prime

}

int main (void) {

// test all nums from 0 to 100 inclusive

for (unsigned num=0; num<=100; ++num) {

if (is_prime (num))

printf ("%d is prime\n", num);

else if (num>0)

printf ("%d is composite\n", num);

else printf ("%d is neither prime nor composite\n", %d);

}

return 0;

}

User Avatar

Wiki User

7y ago

What else can I help you with?

Continue Learning about Engineering

Write a c program to generate all prime numbers in the given range?

look man that would take alot &gt;&gt;&gt; Ill give you the way =============================================================================== this answer i write it now on net ! i read about that befor in it uni where i study i will chick out the answer and re write it best wishes 2024


What BASIC program can compute and display all prime numbers from 1 to 40?

PRINT 2,3,5,7,11,13,17,19,23,29,31,37


Write a c program to find out the prime numbers between 1 to 500?

To write a C program to find prime numbers between 1 to 500, you can use a nested loop structure. In the outer loop, iterate from 2 to 500, and in the inner loop, check if the number is divisible by any number from 2 to the square root of the number. If it is not divisible by any number other than 1 and itself, then it is a prime number. Print out all prime numbers found within the specified range. Remember to include necessary header files, such as &lt;stdio.h&gt;, and use appropriate logic to implement the program efficiently.


Write a programme in bluej to accept two numbers and check whether they are twin prime or not.?

Sure, darling. First, get those two numbers from the user. Then, check if they're both prime and the difference between them is 2. If they pass those tests, congratulations, you've got yourself a pair of twin primes. If not, well, better luck next time. Happy coding, sugar!


How do you write a program in lisp to find if a number is prime or not?

(defun prime (num) (if (&lt; 2 num) (do ((dividend 2 (1 + dividend)) (chk-to (sqrt num))) ((equal (rem num dividend) 0)) (when (&lt;= chk-to dividend) (return t))) t))

Related Questions

How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


How do you write a program in objective c numbers 1-100 prime numbers?

fdsgfhgdfhgdf


Write a C program to find the sum of all prime numbers?

Since there is an infinite set of prime numbers the answer would be infinity.


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


How can I write a program to display prime numbers from 1 to 100?

Write a function that implements an algorithm that checks to see if a particular integer is prime (returning a boolean). Write a program that uses that function on each number from 1 to 100, and if true, displays that number.


Write a program to print first 100 alternative prime numbers?

This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head.


How do you write a c program to get a range from user and give a list of prime numbers?

To get all tutorials of "c programming" Reference:cprogramming-bd.com/c_page2.aspx# prime number


write a pseudocode to accept a number and find if it is prime or not?

Yes


When you write a number as a product of prime numbers?

A number as a product of prime numbers would be &quot;x&quot;.


What to write when describing the properties of prime numbers?

Numbers divisible by 1 &amp; number itself are called prime numbers. These numbers also have the property to be odd numbers.


What is it called to write a a product of prime numbers?

That's called the prime factorization.


How do you write 27 as the product of prime numbers?

Prime factorization of 27 = 3x3x3