-
More Prime Numbers
Ok, I've already posted a thread about a prime number program, and I got a lot of help, thanks to all the people who responded. Now, I need to write another program involving prime numbers. I need to write a program using the following function which determines if a number is prime, and print all of the prime numbers from 1 to 10,000. I know I should use an array, but I'm a rookie at C programming and I can't quite get it correctly. Thanks.
.....code....
...printf( "%d are prime numbers.\n", x);
return 0;
}
//function checkprime definition
int checkprime(num){
int count, result;
if((num == 0) || (num < 0) || (num == 1))
return 2;
for( count = 2; count < num; count ++ ){
result = num % count;
if (result == 0)
return 0;
}
return 1;
}
-
Do you have to use an array (is it a requirement of your task)? Also, use code tags, every time you post code.
Really if you've got your code to test for primes, you just need a loop for printing them. If you want to store them then you would use an array.
-
If you already have the code to calculate if a number is prime, just make it loop from 1 to 10000 and increment a counter each time the prime test passes.
Modify your program so the array is that number in size, and then for the final product, make it assign that number to that slot in the array each time the test passes.
Quzah.
-
Ok, thanks, I think I can get it now.