In this post, I am going to share with you ‘How to calculate the sqrt of a number with CMD?‘. Calculating the sqrt with cmd of a number is a difficult and very time-consuming task. If you are using the traditional ‘Long division method’ or any other Square Root formula with very little practice of the method, then it may become a pain to execute.
CALCULATE SQRT OF A NUMBER WITH CMD
The different approach here is in the method of calculation. Explaining the traditional long division method in the algorithm is probably the most difficult task for me. I thought of doing it smartly – instead of hardly! So, I’m using an alternate method here to solve this quickly with fewer efforts.
SQRT WITH CMD – Algorithm LOGIC
If a number is a
I’m using a loop to calculate the sqrt of perfect squares, and I’m using VBS (instead of defining long division, which would have been difficult) to fulfill my requirement. I think this is the smartest thing to do here in this project.
The CODE – CALCULATE SQRT OF A NUMBER IN
If you read the code carefully, you’ll know how the program works and you even can’t recognize
@echo off :top cls Title Sqrt Calculator... by Kvc echo. echo. set /p "no=Enter The Number to calculate Sqrt : " if not defined no goto top set /a "no=%no%" set sub=1 set sqrt=0 set bkup=%no% Rem Calculating Sqrt here.... Rem Using Property of Perfect sqr, that we have learned in small Classes...that if we subtract odd nos. from perfect sqr,then rem atlast perfect '0' will be left otherwise not.... :] :loop if %no% gtr 0 ( set /a no=%no%- %sub% set /a sub+=2 set /a sqrt+=1 goto loop ) goto end :end REM Checking if the answer is correct..as cmd doesn't support float values.... :[ set /a sqr=%sqrt%*%sqrt% if "%sqr%" == "%bkup%" ( Echo. Sqrt : %sqrt% ) ELSE ( echo. wscript.echo %bkup%^^(1/2^) >"%tmp%\a.vbs" for /f "skip=3 tokens=*" %%a in ('cscript "%tmp%\a.vbs"') do echo. %%a ) echo. pause Del /q "%tmp%\a.vbs" goto top rem #kvc
From the Editor’s Desk
In the end, I created this program when I was just beginning with computer programming and I did not know the possibility of float functions in notepad coding. I hope that you will like this – Give your valuable feedback in the comments field below. We will try to help you out.
HASH Code - For Verification - (SHA-256)
Keep learning, keep sharing….TheBATeam
Be happy, spread happiness…