Last active
July 9, 2021 02:30
-
-
Save carolusquintus/b8757a7c38b44b216513b9765bbae1eb to your computer and use it in GitHub Desktop.
Starting from 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MIN 3 | |
#define MAX 100000 | |
int main() | |
{ | |
int primes[10000] = { 2 }; | |
int totalPrimes = 1; | |
for (int number = MIN; number <= MAX; ++number) | |
if (number % 2 == 0) | |
continue; | |
else | |
for (int i = 0; i < totalPrimes; ++i) | |
if (number % primes[i] == 0) | |
break; | |
else if (i == totalPrimes - 1) { | |
primes[totalPrimes++] = number; | |
break; | |
} | |
else | |
continue; | |
for (int j = 0; j < totalPrimes; ++j) | |
printf("%d, ", primes[j]); | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment