Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
sol.c File Reference

Problem 7 solution. More...

#include <stdio.h>
#include <stdlib.h>
Include dependency graph for sol.c:

Functions

int main (void)
 Main function. More...
 

Detailed Description

Problem 7 solution.

See also
Another version: problem_7/sol2.c

Function Documentation

◆ main()

int main ( void  )

Main function.

Returns
0 on exit
13 {
14  char *sieve;
15  size_t i;
16  unsigned count = 0;
17  size_t n = 1000000;
18  const unsigned target = 10001;
19 
20  sieve = (char *)calloc(n, sizeof(char));
21  for (i = 2; i < n; i++)
22  {
23  if (!sieve[i])
24  {
25  size_t j;
26  count++;
27  if (count == target)
28  {
29  printf("%lu\n", i);
30  break;
31  }
32  for (j = i * 2; j < n; j += i)
33  {
34  sieve[j] = 1;
35  }
36  }
37  }
38  free(sieve);
39  return 0;
40 }
int count(int *arr, const int size)
Count func counts the number of prime numbers.
Definition: prime_seive.c:42
Here is the call graph for this function: