answersLogoWhite

0


Best Answer

You need two utility functions. The first determines if a given number is prime or not. The second finds the next prime after a given number.

The following function can be used to determine if a given integer is prime:

bool is_prime (const unsigned num) {

if (num<2) return false;

if (0==(num%2)) return num==2;

unsigned max_factor = (unsigned) sqrt ((double) num) + 1;

unsigned factor;

for (factor=3; factor<max_factor; ++factor)

if (0==(num%factor)) return false;

return true;

}

The following function can be used to determine the next prime after the given integer:

unsigned next_prime (unsigned num) {

while (!is_prime (++num));

return num;

}

Now you can print a series of primes using the following:

int main (void) {

unsigned num=1;

while (num<10000) {

num = next_prime (num);

printf ("%d is prime\n", num);

}

return 0;

}

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a c program to find prime numbers between 1 to 10000 using functions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How many palindrome numbers are there between 9000 10000?

there are 10 palindromic numbers between 9000 and 10000 9009,9119,9229,9339,9449,9559,9669,9779,9889,9999


What are the palindromic numbers between 0 and 10000?

1097


How many numbers between 1000 and 10000 have 3 zeros in them?

There are eight such numbers.


What are the square numbers from 576 to 10000?

The square numbers integers between 576 and 10000 (and their square roots, in the left column) are: 245762562526676277292878429841309003196132102433108934115635122536129637136938144439152140160041168142176443184944193645202546211647220948230449240150250051260152270453280954291655302556313657324958336459348160360061372162384463396964409665422566435667448968462469476170490071504172518473532974547675562576577677592978608479624180640081656182672483688984705685722586739687756988774489792190810091828192846493864994883695902596921697940998960499980110010000


What number lies between 8500 and 10000?

There is an infinity of numbers between 8500 and 10000. For example 8605+sqrt(2).


What numbers will be rounded to 10000 when rounded to the nearest thousand?

10000


How many whole numbers between 1 and 10000?

9998.


How many palindromic numbers between 10 and 10000?

1089


How many prime numbers between 1 and 10000?

1229


How many numbers between 1000 and 10000 have 0 in them?

999


If 11 equals 2 numbers 111 equals 3 numbers 1111 equals 4 How many numbers between 1 and 10000?

If you mean strictly between , so that 1 and 10000 are both excluded, the answer is 38,888


How many numbers between 1 and 10000 are divisible by 3?

Int(10000/3) = Int(3333.3) = 3333