# what do you you mean, this prog doesnt work??

• 02-28-2002
...
what do you you mean, this prog doesnt work??
someone asked earlier about a program involving prime numbers, and i figured they would be pretty easy to work with, so i threw together a simple program to show all of the prime numbers less than 1000. this program looks like it should run perfectly from what i see, but it seems that it comes up with no results at all.

my program looks like this:

#include <stdio.h>
#include <stdlib.h>

void prime();

int i=1000,x=0,y,z;

void main(){

printf("All of the prime numbers less than 1000:\n");

while ( i > 2 ){
z=0;
x=i;
prime();
i = --i;
}

printf("2\n1\n");
system ("PAUSE");
}

void prime (){

while ( x != 1 ){

y = i % (x-1);
x = --x;

if ( y == 0 ){
x = 1;z = 1;}

}

if ( z == 0 ){
printf("%d\n", i); }

}

and the output looks like this:

All of the prime numbers less than 1000:
2
1
press any key to continue...

the prime() function is supposed to check for divisibility in every number below i. if any number divides evenly then it sets z to 1. if z never gets set to 1, and x gets all the way to 1, it prints i and then subtracts one from i and repeats the loop. why doesnt this ever print anything?
• 02-28-2002
...
ok, i fixed what i thought was the problem (it only checks for if x = 1, but if x = 2, then it divides by x - 1 which is one, and every number is divisible by 1 so it ends the loop and doesnt print),

BUT

now i have another problem..... i changed the while statement to

while ( x != 2 )

and now i get an illegal opperation.

*sigh*....
• 02-28-2002
...
woo, fixed it.

no thanks to any of you :p