All pastes #255737 Raw Edit

Cobi

public c v1 · immutable
#255737 ·published 2006-11-23 08:54 UTC
rendered paste body
/* Primes finder (primes.c) by Cobi *//* * We need this library (printf?). */#include <stdio.h>/* * We need this library for atoi(). */#include <stdlib.h>int main (int argc, char **argv) { /* Our main program. */	/* Make sure we have the correct arguementes. */	if (argc < 2) {		/* We don't, complain. */		printf ("This binary requires the start");		printf ("and stop values as arguements 1 ");		printf ("and 2.\nExample: %s <start> <st",argv[0]);		printf ("op>\n");		return 0;	}	/* We initialize our outer loop variables. */	unsigned long bigcounter = atoi(argv[1]);	unsigned long upperbound = atoi(argv[2]);	/* Then we initialize our inner loop variables. */	unsigned long to = 0;	unsigned long counter = 0;	unsigned long halfto = 0;	/*	 * And then we initialize our variable to	 * hold the status of the current check.	 */	unsigned short found = 0;	/*	 * We make a big loop through each integer	 * between argv[1] and argv[2].	 */	while (bigcounter <= upperbound) {		/* Reset any variables for the inner loop. */		counter = 2;		to = bigcounter;		found = 0;		halfto = to / 2;		/*		 * We make an inner loop to loop through		 * each integer between 2 and half of the		 * integer we are checking for primality.		 */		while (counter < halfto) {			/*			 * We check to see if the counter devides			 * evenly into the integer we are checking			 * for primality.			 */			if (to % counter == 0) {				/* It is not prime, set found = 1 */				found = 1;				/* and set counter so the loop exits. */				counter = to;			}			/* Increment the counter. */			counter++;		}		/*		 * Check to see if the loop exited normally		 * as opposed to prematurely.		 */		if (found == 0) {			/*			 * If it exited normally, we found			 * ourselves a prime!  Print it out			 * so the owner can see.			 */			printf("%d\n",to);		}		/* Increment the counter. */		bigcounter++;	}	/* Exit successfully. */	return 0;}