Type your ugBASIC program here (remember: keywords like PRINT must be UPPERCASE!).
Click on Build menu to select the target: you will download the compiled binary file!

4 CLS 5 REM inizializzo limite massimo e array di flag 6 REM nums(x) = 0 -> x dentro 7 REM nums(x) = 1 -> x fuori 10 CONST maxn=400:DIM nums(maxn) 12 REM inizializzo timer e contatore di numeri primi 15 TI=0:np%=0 17 REM esamino tutti i numeri da 2 a maxn 20 FOR i=2 TO maxn 25 REM se il numero i è fuori dal crivello, passo al successivo 30 IF nums(i) <> 0 THEN : GOTO 90 : ENDIF 35 REM altrimenti i è primo. incremento contatore primi 36 REM stampo il primo i e mi preparo a generare i multipli 40 np%=np%+1:PRINT i,:k%=1 45 REM calcolo il multiplo come i*k (k=1,2,..) 46 REM finchè il multiplo è <= maxn 47 REM poi passo ad esaminare il prossimo i 50 multiplo=i*k% 60 IF multiplo>maxn THEN : GOTO 90 : ENDIF 70 REM metto il multiplo fuori dal crivello 80 nums(multiplo)=1 82 REM calcolo il prossimo multiplo da escludere 85 k%=k%+1:GOTO 50 90 NEXT 95 REM stampo il contatore dei numeri primi e il tempo trascorso 100 REM PRINT:PRINT "contaprimi: ";np% 110 REM PRINT "ti ";TI 115 ct=(TI/60) 120 IF ct>60 THEN : ct=ct-60 : m%=m%+1 : GOTO 120 : ENDIF 130 PRINT:PRINT "time: ";m%;" min ";ct;" s" 140 PRINT CHR$(126);"(";c%;") =";np%

Welcome to the ugBASIC sandbox!

This tool was designed to quickly test whether the code you are writing compiles correctly and determines the desired results. Since the source is compiled thanks to dedicated servers, separate from the browser you are using, some commands are not available: for example, you cannot load external files or resources by using the LOAD command. If you need to develop a program with a complete tool, we recommend installing the executables or the UGBASIC-IDE.

Unless required by applicable law or agreed to in writing, this website is given on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.