answersLogoWhite

0

Still curious? Ask our experts.

Chat with our AI personalities

SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
More answers
User Avatar

Wiki User

15y ago

I once tried this, but it was rather slow. "kwad" is short for "kwadraat", which is dutch for square (algebra). It was supposed to write all primes to the prime.txt file, and save the files when you decided to quit the program, however, I never finished those parts.
@echo off
IF NOT EXIST prime.txt goto reset
IF NOT EXIST save.dat goto reset
IF NOT EXIST max.dat goto reset
goto starter

:reset
echo ^2>prime.txt
echo ^3>>prime.txt
echo ^5>>prime.txt
echo ^7>save.dat
echo ^2>max.dat
pause

:starter
set /p current= set /p max=

:numbercalc
echo %current%
set /a kwad=(%max%+1)*(%max%+1)
if %kwad% LEQ %current% set /a max=%max%+1
set temp=3
:try
set /a t=%current%/%temp%
set /a u=%t%*%temp%
if %u% EQU %current% goto noprime
set /a temp+=1
if %temp% GTR %max% goto endtry
goto try
:endtry
echo ^%current%>>prime.txt
:noprime
set /a current+=2
if %current% EQU 101 goto end
goto numbercalc

:end
pause

User Avatar

Add your answer:

Earn +20 pts
Q: Batch file to display prime numbers from 1-100?
Write your answer...
Submit
Still have questions?
magnify glass
imp