China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 09:10
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Numerical Calculation]Square roots of integers from 1 to 99 View 1,940 Replies 4
Original Poster Posted 2008-09-20 17:25 ·  中国 广东 揭阳 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Also published on bathome
http://bbs.bathome.cn/viewthread.php?tid=1791&page=1&extra=page%3D1
If there are decimals, keep 3 decimal places.

@echo off
:action
set /p input="(1-99):"
if "%input%"=="" goto :action
set /a a=0,n=0
:a
set /a a+=1,a1=0
:a1
set /a a1+=1,test=(n*10+a1)*(n*10+a1)
if %test% equ %input% (echo %a1% &pause &goto :end)
if %test% lss %input% (goto :a1)
set /a n=n*10+a1-1,input*=100
if %a% lss 4 goto :a
echo %n:~0,1%.%n:~1%
pause>nul
:end
echo,&set input=
goto :action



[ Last edited by 523066680 on 2008-9-21 at 07:29 AM ]
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
moniuming +8 2008-09-20 19:24
lxmxn +8 2008-09-21 09:01
Floor 2 Posted 2008-09-21 09:08 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
That's good, it has been collected into the top-sticked Classic Thread Classification Index in Batch Processing Room.
Floor 3 Posted 2008-09-21 09:12 ·  中国 广东 江门 电信
中级用户
★★
Credits 338
Posts 175
Joined 2007-10-21 15:30
18-year member
UID 100351
Gender Male
Status Offline
Take a seat...
This time it's much more efficient
Floor 4 Posted 2008-09-21 09:18 ·  中国 广东 揭阳 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Principle: Compare digit by digit. For example, input 2.
0*0=0
1*1=1
2*2=4 4>2 so the first digit is 1.
Then 1.1*1.1
1.2*1.2
1.3*1.3……
1.4*1.4
1.5*1.5 = 2.25 >2 so take 1.4
And so on. Everyone is puzzled: Batch processing has no decimals.
Then calculate with integers, and then add a decimal point to it.
Floor 5 Posted 2008-09-21 09:25 ·  中国 广东 揭阳 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Thanks for everyone's support! I love cn-dos!
Forum Jump: