Está en la página 1de 2

@echo off

::Division con decimales


::Baseado en el code

title CAIDA LIBRE

echo Calcula la posicion de el objeto en caida libre lanzado desde 250 metros
de altura
:main
echo.
echo.
echo.
set did=
set div=
set max=
set h=250
set g=
set t=
set /p g=Introduce la gravedad:
if "%g%"=="" goto main
if "%g%"=="9.8" (
echo Error. La gravedad no puede ser 9.8.
pause>nul
exit
)
set /p t=Introduce el tiempo:
if "%t%"=="" goto main
if "%t%"=="0" (
echo Error. Debe ser un tiempo que no sea cero
set /a did=2*%h% - %g%*%t%*%t%
set /a div=2
set /p max=Introduce el numero maximo de decimales (por defecto 30):
if "%did%"=="" goto main
if "%div%"=="" goto main
if "%max%"=="" set max=30
if "%max%"=="0" set max=30
set /a xxx=%did%*1
if not "%xxx%"=="%did%" goto main
set /a xxx=%div%*1
if not "%xxx%"=="%div%" goto main
set /a xxx=%max%*1
if not "%xxx%"=="%max%" goto main
echo.
if %div%==0 (
echo Error. Division por cero.
pause>nul
exit
)
set /a divno0=%did%/%div%
set /a mult1=%divno0%*%div%
set /a resi0=%did%-%mult1%
if %resi0%==0 (
goto exacto
)
set p=0
echo Calculando...
echo.
:a
set /a nu=nu+1
set temp1=resi%p%
set temp2=divno%nu%
set temp3=mult%nu%
call:func1 %%%temp1%%%0
call:func2 %%%temp2%%% %%%temp2%%%
call:func3 %%%temp1%%%0 %%%temp3%%%
goto sig
:func1
set /a divno%nu%=%1/%div%
goto:EOF
:func2
set /a mult%nu%=%1*%div%
goto:EOF
:func3
set /a resi%nu%=%1-%2
goto:EOF
:sig
set /a p=p+1
set temp=resi%nu%
call:funcion2 %%%temp%%%
goto sig2
:funcion2
set tempvalue=%1
goto:EOF
:sig2
If not %nu%==%max% if not %tempvalue%==0 goto a
For /L %%I IN (1,1,%nu%) DO (
call:funcion3 %%%%divno %%I%%%%
)
goto exacto
:funcion3
call:funcion7 %1%2
goto seguir
:funcion7
set tmpvar=%1
goto:EOF
:seguir
set decimal=%decimal%%tmpvar%
goto:EOF
:exacto
if not "%decimal%"=="" set decimal=.%decimal%
echo Resultado: %divno0%%decimal%
pause>nul
exit
decimales.txt
Mostrando decimales.txt.

También podría gustarte