[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: puzzle



Steven Ketcham (ketcham@earthlink.net) wrote:
: include <stdio.h>
: /* Create a program to find and calculate the difference between the fifth
: * and tenth prime number.
: */
: main()
: {
: 	int n, count, i, array [2];
: 	count=2, i=2;
: 	while (count<10)
: 		{
: 	for (n=2; (n==i-1 && i%n!=0); n++);/*
: ****************************************
:    I am using "i" as my variable to keep track of what number 
: we're testing. I am using the "n" loop to factor out "i". 
: I have "n" incrementing until it is one less than "i". I could have "n" stop 
: at half of "i's" value (as in the documantation) because there will be no 
: factors after that. I could also change "n==i-1" to "n<i".
:    I want my loop to break if "n" is one less than "i" and if
: there is no remainder when "i" is divided by "n". In looking
: at it I think I need to change "i%n!=0" to "i%n==0".
: So in talking through my statement I think it should say
: "for (n=2; (n<i && i%n==0);n++);
: ******************************************/
: 	if (n%i!=0){
: 		 count++;
: 		if (count==5)
: 			 array [0]=count;
: 		if (count==10)
: 		 	array [1]=count;}
: }
: 		i++;

: > This increment of i is not within any loop body, and none of the
: > following code references i, therefore in this program it is not
: > doing anything useful. Perhaps you are missing a set of {}'s which
: > define the body of one of your loops.

: /*************************************************************
:  Your right!! "i++" doesn't do anything! I didn't understand what you were 
: saying. I was thinking that the -while- loop would break when "count" equaled 
: ten. My understanding was that I had:
: 		While (count<10)
: 			i++
: with conditional staments inbetween that would increment "count".
: Somehow I need a break(?) perhaps in the "if (count==10) - array [1]=count" 
: line? I believe all the {} are there though.
: **************************************************************/
: 	
: 	printf ("The difference between the fifth prime and the tenth prime 
: is %d\n",array[1]-array[0]);
: 	printf ("The first prime is %d\n",array[0]," and the second prime is 
: %d\n", array[1]);
: 	return 0;
: }


: Dave Dunfield wrote:
: > 
: > This posting smells of a class assignment, so I will not give you a complete
: > answer, nor have I attempted to figure out exactly what your program is
: > doing. There are problems much more basic than that with it:
: > 
: > The program as posted contains several syntax errors, and will not compile
: > with Micro-C or any other C compiler. Both the Micro-C technical manual,
: > and the "Introduction to C" document distributed with the compiler contain
: > detailed descriptions/examples of these constructs:
: > The problem is taken from an old book called "The Commodore Programer's 
: Challenge" by Steven Chen. It was what my local library had available on the 
: subject. No, it is not a class assignment but it looks that way.

: The program now compiles but does not work... as of yet. Thanks.

--
**********begin r.s. response*****************

	posting suggests that this
	student programmer is self teaching
		the 'c' programming language
	with a shareware compiler and
	"obsolete" programming books from the
	local library!

	possibly,  tenaciously done,
	this might work as well,  or better,
	than current college programs...

	certainly the assignment posed is,
	on a traditional basis,  college level!!!

	if old,  possibly disused,
	computers and freely available
	software were to be used
	in this way,
	then,
	at very little cost,
	a vibrant culture of sophisticated
	programming might evolve!!!

**********end r.s. response*******************
Ralph Silverman
z007400b@bcfreenet.seflin.lib.fl.us




--

Ralph Silverman
z007400b@bcfreenet.seflin.lib.fl.us