answersLogoWhite

0

Still curious? Ask our experts.

Chat with our AI personalities

BeauBeau
You're doing better than you think!
Chat with Beau
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
More answers

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

Wiki User

15y ago
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