answersLogoWhite

0

Still curious? Ask our experts.

Chat with our AI personalities

LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
JudyJudy
Simplicity is my specialty.
Chat with Judy
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