Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
Loading...
Searching...
No Matches
Misc

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

Functions

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

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}
static void test()
Test implementations.
Definition prime_sieve.c:56
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}
const unsigned long long MAX_SIZE
for assert for standard input output for general purpose standard library
Definition prime_sieve.c:11

◆ 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}
void prime(int *p)
Prime Sieve works in O(nlogn) time.
Definition prime_sieve.c:21
Here is the call graph for this function: