Add program: primes
This commit is contained in:
Binary file not shown.
@@ -12,7 +12,7 @@ void shell_install()
|
|||||||
char input_buffer[BUFFER_SIZE];
|
char input_buffer[BUFFER_SIZE];
|
||||||
colorputs("blankos> ", 9);
|
colorputs("blankos> ", 9);
|
||||||
get_input(input_buffer, BUFFER_SIZE);
|
get_input(input_buffer, BUFFER_SIZE);
|
||||||
printf("\n");
|
puts("\n");
|
||||||
|
|
||||||
// Childish shell
|
// Childish shell
|
||||||
if (strcmp(input_buffer, "") == 0)
|
if (strcmp(input_buffer, "") == 0)
|
||||||
@@ -21,7 +21,7 @@ void shell_install()
|
|||||||
}
|
}
|
||||||
else if (strcmp(input_buffer, "help") == 0)
|
else if (strcmp(input_buffer, "help") == 0)
|
||||||
{
|
{
|
||||||
printf("This is the Blank Operating System\ndesigned for fun by xamidev\n\nCommand help:\n\n\thelp - shows this message\n\tpanic - makes the kernel panic\n\twords - generates random words\n");
|
printf("This is the Blank Operating System\ndesigned for fun by xamidev\n\nCommand help:\n\n\thelp - shows this message\n\tpanic - makes the kernel panic\n\twords - generates random words\n\tprimes - computes prime numbers\n");
|
||||||
}
|
}
|
||||||
else if (strcmp(input_buffer, "panic") == 0)
|
else if (strcmp(input_buffer, "panic") == 0)
|
||||||
{
|
{
|
||||||
@@ -31,6 +31,10 @@ void shell_install()
|
|||||||
{
|
{
|
||||||
program_words();
|
program_words();
|
||||||
}
|
}
|
||||||
|
else if (strcmp(input_buffer, "primes") == 0)
|
||||||
|
{
|
||||||
|
program_primes();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
printf("Unknown command %s\n", input_buffer);
|
printf("Unknown command %s\n", input_buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/programs/primes.c
Normal file
23
src/programs/primes.c
Normal 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");
|
||||||
|
}
|
||||||
@@ -2,5 +2,6 @@
|
|||||||
#define PROGRAMS_H
|
#define PROGRAMS_H
|
||||||
|
|
||||||
void program_words();
|
void program_words();
|
||||||
|
void program_primes();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user