/** * PRIMESMAIN.C * * Exercise solution 2.5. (C By Dissection Chap. 4, ex. 12) * * Computes a list of prime numbers. * 26-Feb-03 by Dimon **/ /** * INCLUDE statements **/ #include "primes.h" /** * The main function **/ int main(void) { /* Declaration of variables */ int i = 1, numPrimes = 0, value = 2; int status = 0; /* Display program header and enter number of primes to calculate */ printf("V1: Primes will be printed\n"); printf("----------------------\n"); printf("\n"); printf("How many do you want to see? "); scanf("%d",&numPrimes); /* 2 is the only even prime number, so it is treated as a special case */ if (numPrimes > 0) { printf("%6d: %10d", i, value); } printf("\n"); value = 3; /* value is set to the second smallest prime */ /* A FOR loop calculates and prints out the results */ for(i = 2; i <= numPrimes; i++) { while (!is_prime(value)) { value += 2; /* Only the odd integers need to be tested */ } printf("%6d: %10d", i, value); printf("\n"); value += 2; /* Increment to the next potential prime number */ } /* End of FOR loop */ /* Terminate program */ return status; } /* END OF MAIN */