From 446296a5a885406e9f004d8202df25abdf04184d Mon Sep 17 00:00:00 2001 From: MatMasIt Date: Sat, 2 Oct 2021 15:56:23 +0200 Subject: [PATCH] Update primes.mga --- examples/primes.mga | 51 +++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/examples/primes.mga b/examples/primes.mga index 49b6775..3aebb7c 100644 --- a/examples/primes.mga +++ b/examples/primes.mga @@ -1,23 +1,34 @@ -INT tot -INT n +INT i INT j -INT te -IN INT tot numero massimo -SET n 1 -:scn - SET j 2 - OUT $n$\n - :sieve - MOD n j te - #OUT \n- $te$ -\n - JME scr j n +INT n +INT c +INT modr + +IN INT n Enter the number till which you want prime numbers\n + +OUT Prime numbers are:\n + +SET i 2 +:loopi + SET c 0 + SET j 1 + :loopj + MOD i j modr + JE increasec modr 0 + :increasecback INC j 1 - JM sieve te 0 - INC n -JLE scn n tot + JLE loopj j i + JE printn c 2 + :printback + INC i 1 +JLE loopi i n END -:scr -#OUT $j$ sas\n -SET j 2 -INC n -JMP sieve +:increasec + INC c 1 + JMP increasecback + +:printn + OUT $i$\n + JMP printback + +