Add program: primes

This commit is contained in:
xamidev
2024-07-24 20:26:49 +02:00
parent 05b7acd931
commit 13a72cc543
5 changed files with 30 additions and 2 deletions

23
src/programs/primes.c Normal file
View File

@@ -0,0 +1,23 @@
#include "../libc/stdint.h"
#include "../libc/stdio.h"
#define PRIMES_MAX 1000000
bool isPrime(int n)
{
if (n == 1 || n == 0) return false;
for (int i=2; i<= n/2; i++) if (n%i == 0) return false;
return true;
}
void program_primes()
{
for (long long x=0; x<PRIMES_MAX; x++)
{
if (isPrime(x))
{
printf("%d ", x);
}
}
puts("\n");
}

View File

@@ -2,5 +2,6 @@
#define PROGRAMS_H
void program_words();
void program_primes();
#endif