answersLogoWhite

0


Best Answer

101

User Avatar

Felton O'Hara

Lvl 10
3y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y 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

This answer is:
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