diff options
| author | hachem <im@hachem.wtf> | 2026-10-12 23:08:48 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-10-12 23:08:48 +0200 |
| commit | 6a5543bb8f1f535ca49737bcd7be0cafca3b2a08 (patch) | |
| tree | bb137b732a1d122aeace46c550733f4793d84601 /user/primes.c | |
| parent | 59794d0b999e544a94230d9562bf2b99d2ed74c7 (diff) | |
Diffstat (limited to 'user/primes.c')
| -rw-r--r-- | user/primes.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/user/primes.c b/user/primes.c index 49c545a..5501c32 100644 --- a/user/primes.c +++ b/user/primes.c @@ -1,22 +1,19 @@ -#include "user.h" +#include <stdio.h> +#include <stdlib.h> -void _start(void) +int main(void) { - put("primes up to N, enter N (empty line quits)\n"); + printf("primes up to N, enter N (empty line quits)\n"); char line[32]; for (;;) { - put("> "); - int length = read_line(line, 32); - put("\n"); + printf("> "); + int length = readline(line, 32); + printf("\n"); if (length == 0) break; - long limit = 0; - for (int position = 0; position < length; position++) - if (line[position] >= '0' && line[position] <= '9') - limit = limit * 10 + (line[position] - '0'); - + long limit = atol(line); int count = 0; for (long candidate = 2; candidate <= limit; candidate++) { @@ -29,14 +26,11 @@ void _start(void) } if (prime) { - put_int(candidate); - put(" "); + printf("%ld ", candidate); count++; } } - put("\n"); - put_int(count); - put(" primes\n"); + printf("\n%d primes\n", count); } - sys_exit(0); + return 0; } |
