Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
Misc

variable upto which prime numbers are to be found out More...

Functions

void prime (int *p)
 Prime Sieve works in O(nlogn) time. More...
 
int count (int *arr, const int size)
 Count func counts the number of prime numbers. More...
 
static void test ()
 Test implementations. More...
 
int main (int argc, const char *argv[])
 Main function. More...
 

Detailed Description

variable upto which prime numbers are to be found out

Function Documentation

◆ count()

int count ( int *  arr,
const int  size 
)

Count func counts the number of prime numbers.

Parameters
arrcontains the prime numbers
sizedenotes upto which prime numbers are to be found out
Returns
count of prime numbers
42  {
43  int k=0;
44  for(int i=0;i<=size;i++){
45  if(arr[i]==1){
46  k++;
47  }
48  }
49  return k;
50 }

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Main function.

Parameters
argccommandline argument count (ignored)
argvcommandline array of arguments (ignored)
Returns
0 on exit
74 {
75  test(); // execute the tests
76  return 0;
77 }
Here is the call graph for this function:

◆ prime()

void prime ( int *  p)

Prime Sieve works in O(nlogn) time.

Parameters
parray to be updated
Returns
void
22 {
23  for(long long int i=3;i<=MAX_SIZE;i+=2) { p[i]=1; }
24  for(long long int i=3;i<=MAX_SIZE;i+=2)
25  {
26  if(p[i]==1) {
27  for(long long int j=i*i;j<=MAX_SIZE;j+=i) {
28  p[j]=0;
29  }
30  }
31  }
32  p[2]=1;
33  p[0]=p[1]=0;
34 }

◆ test()

static void test ( void  )
static

Test implementations.

Returns
void
57 {
58  // Test Case 1
59  const int size = 10; /* array size */
60  printf("Test Case 1...");
61  int arr[1000005]={0}; /* array to store prime numbers */
62  prime(arr);
63  assert(count(arr,size)==4);
64  printf("Passed\n");
65 }
Here is the call graph for this function:
MAX_SIZE
const unsigned long long MAX_SIZE
for assert for standard input output for general purpose standard library
Definition: prime_seive.c:11
count
int count(int *arr, const int size)
Count func counts the number of prime numbers.
Definition: prime_seive.c:42
prime
void prime(int *p)
Prime Sieve works in O(nlogn) time.
Definition: prime_seive.c:21
test
static void test()
Test implementations.
Definition: prime_seive.c:56