variable upto which prime numbers are to be found out
More...
|
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.
|
|
variable upto which prime numbers are to be found out
◆ count()
int count |
( |
int * |
arr, |
|
|
const int |
size |
|
) |
| |
Count func counts the number of prime numbers.
- Parameters
-
arr | contains the prime numbers |
size | denotes 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
-
argc | commandline argument count (ignored) |
argv | commandline array of arguments (ignored) |
- Returns
- 0 on exit
74{
76 return 0;
77}
static void test()
Test implementations.
Definition prime_sieve.c:56
◆ prime()
Prime Sieve works in O(nlogn) time.
- Parameters
-
- 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
59 const int size = 10;
60 printf("Test Case 1...");
61 int arr[1000005]={0};
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