
Untitled
By: a guest on
May 15th, 2012 | syntax:
C | size: 0.89 KB | hits: 17 | expires: Never
#include <stdio.h>
#include <math.h>
int main (void)
{
unsigned int p, d, n, N, count = 0;
unsigned char isPrime;
printf ("Give me the interval: ");
scanf ("%i %i", &p, &n);
if ( p == 0 || p == 1 )
p = 2;
if ( p > n )
printf ("The first number must be less or equal to the second number!\n");
else {
printf ("The prime numbers between %u and %u are:\n\n", p, n);
for ( ; p <= n; ++p ) {
isPrime = 1;
N = sqrt(p);
for ( d = 2; d <= N; ++d ) {
if ( p % d == 0 ) {
isPrime = 0;
break;
}
}
if ( isPrime != 0 ) {
printf ("%i ", p);
++count;
}
}
printf ("\n\nPrime numbers in total: %i\n", count);
}
return 0;
}