----------------------------------------------------------------------- @echo off SET startchar=%2 SET length=%3 SET string=%1 CALL SET substring=%%string:~%startchar%,%length%%% ECHO %substring% ----------------------------------------------------------------------- script.bat sir_de_caractere pozitie_start lungime_secventa ----------------------------------------------------------------------- 1. script.bat abcdefghijklmnopqrstuvwxyz 0 5 2. script.bat abcdefghijklmnopqrstuvwxyz -5 5 3. script.bat abcdefghijklmnopqrstuvwxyz 3 7 ----------------------------------------------------------------------- @echo off SET subsir=%2 SET string=%1 CALL SET substring=%%string:%subsir%=%% ECHO %substring% ----------------------------------------------------------------------- script.bat sir_de_caractere subsir_de_eliminat ----------------------------------------------------------------------- 4. script.bat abcdefghijklmnopqrstuvwxyz klmnop ----------------------------------------------------------------------- @echo off SET subsir=%2 SET string=%1 SET newsir=%3 CALL SET substring=%%string:%subsir%=%newsir%%% ECHO %substring% ----------------------------------------------------------------------- script.bat sir_de_caractere subsir_vechi subsir_nou ----------------------------------------------------------------------- 5. script.bat abcdefghijklmnopqrstuvwxyz klmnop 12345678910 ----------------------------------------------------------------------- @echo off SET startchar=%2 SET endchar=%3 SET string=%1 CALL SET substring=%%string:~%startchar%,%endchar%%% ECHO %substring% ----------------------------------------------------------------------- script.bat sir_de_caractere pozitie_start pozitie_stop ----------------------------------------------------------------------- 6. script.bat abcdefghijklmnopqrstuvwxyz 1 -1 ----------------------------------------------------------------------- @echo off SET startchar=%2 SET endchar=-%2 SET string=%1 CALL SET substring=%%string:~%startchar%,%endchar%%% ECHO %substring% ----------------------------------------------------------------------- script.bat sir_de_caractere lungime ----------------------------------------------------------------------- 7. script.bat "abc def ghijklmnopqrstuvwxyz" SET string=%~1 CALL SET substring=%%string: =%%% ECHO %substring% ----------------------------------------------------------------------- @echo off set list=1 2 3 4 (for %%a in (%list%) do ( echo %%a )) ----------------------------------------------------------------------- script.bat ----------------------------------------------------------------------- 8. script.bat ----------------------------------------------------------------------- @echo off set /A a=%1 set /A b=%2 if %a% lss %b% (echo "a=%a% este mai mic decat b=%b%") else (echo "a=%a% este mai mare decat b=%b%") ----------------------------------------------------------------------- 9. script.bat 15 9 ----------------------------------------------------------------------- @echo off set /A a=%1 set /A b=%2 set /A c=%3 set /A r1=%a%*%c%*%c%+%b% set /A r3=5*%c%-7 if %c% lss 0 (echo "E(%c%)=%r1%") else (if %c% == 0 (echo "E(%c%)=2") else (echo "E(%c%)=%r3%")) ----------------------------------------------------------------------- 10. script.bat 1 2 -3 script.bat 1 2 3 script.bat 1 2 0 ----------------------------------------------------------------------- 11. a) script.bat 10 20 30 40 50 ----------------------------------------------------------------------- @ECHO OFF SET /A suma=0 :Loop IF "%1"=="" GOTO completed FOR %%F IN (%1) DO ( IF %1 GTR 0 ( SET /A suma=%suma%+%1 ) ) SHIFT GOTO Loop :completed echo %suma% ----------------------------------------------------------------------- 11. b) script.bat 10 20 30 40 50 ----------------------------------------------------------------------- @echo off SET /A prod=1 :start SET /A numar = %1 SET /A divnumber = %numar% / 2 SET /A prodnumber = %divnumber% * 2 IF %numar% EQU %prodnumber% (goto :odd) ELSE (goto :even) :odd SET /A prod=%prod% * %numar% :even if "%~2" NEQ "" ( shift goto :start ) echo %prod% ----------------------------------------------------------------------- 11. b) - varianta de rezolvare 2 @echo off setlocal enabledelayedexpansion set /a prod=1 for %%a in (%*) do ( echo nr=%%a set /a rest=%%a %% 2 echo rest=!rest! if !rest! EQU 0 set /a prod=!prod! * %%a echo prod=!prod! ) ----------------------------------------------------------------------- 11. c) script.bat -10 -20 -30 -40 -50 ----------------------------------------------------------------------- @echo off SET /A suma = 0 SET /A pozitie = 1 :start SET /A numar = %1 SET /A divnumber = %pozitie% / 2 SET /A prodnumber = %divnumber% * 2 IF %pozitie% NEQ %prodnumber% (IF %numar% LSS 0 (goto :odd) ELSE goto :even) ELSE (goto :even) :odd SET /A suma=%suma% + %numar% :even SET /A pozitie = %pozitie% +1 if "%~2" NEQ "" ( shift goto :start ) echo %suma% ----------------------------------------------------------------------- 11. c) - varianta de rezolvare 2 @echo off SET /A suma = 0 SET /A pozitie = 1 :start SET /A numar = %1 IF %numar% LSS 0 (goto :odd) ELSE goto :even :odd SET /A suma=%suma% + %numar% :even SET /A pozitie = %pozitie% + 2 if "%~2" NEQ "" ( if "%~3" NEQ "" ( shift shift goto :start ) ) echo %suma% ----------------------------------------------------------------------- @echo off setlocal enabledelayedexpansion SET /A suma = 0 SET /A pozitie = 1 for %%a in (%*) do ( echo nr=%%a set /a rest = %pozitie% %% 2 echo rest=!rest! if !rest! EQU 1 ( IF %%a LSS 0 ( set /a suma=!suma!+%%a) ) ) echo suma=%suma% ----------------------------------------------------------------------- 11. d) script.bat 6 7 17 9 12 ----------------------------------------------------------------------- @echo off SET /A suma = 0 SET /A pozitie = 0 :start SET /A numar = %1 SET /A divnumber = %numar% / 5 SET /A prodnumber = %divnumber% * 5 SET /A rest = %numar% - %prodnumber% IF %rest% EQU 2 ( SET /A suma=%suma% + %numar% SET /A pozitie = %pozitie% +1 ) if "%~2" NEQ "" ( shift goto :start ) SET /A media = %suma% / %pozitie% echo %media% ----------------------------------------------------------------------- 11. c) varianta de rezolvare 2 @echo off SET /A suma = 0 SET /A pozitie = 0 :start if [%1] == [] goto :final SET /A numar = %1 SET /A divnumber = %numar% / 5 SET /A prodnumber = %divnumber% * 5 SET /A rest = %numar% - %prodnumber% IF %rest% EQU 2 ( SET /A suma=%suma% + %numar% SET /A pozitie = %pozitie% +1 ) shift goto :start :final SET /A media = %suma% / %pozitie% echo %media% ----------------------------------------------------------------------- 11 c) varianta de rezolvare 3 @echo off SET /A suma = 0 SET /A pozitie = 0 :start if [%1] == [] goto :final SET /A numar = %1 SET /A rest = %numar% %% 5 IF %rest% EQU 2 ( SET /A suma=%suma% + %numar% SET /A pozitie = %pozitie% +1 ) shift goto :start :final SET /A media = %suma% / %pozitie% echo %media% ----------------------------------------------------------------------- 11. c) varianta de rezolvare 4 @echo off setlocal enabledelayedexpansion SET /A suma = 0 SET /A numere = 0 for %%a in (%*) do ( set /a rest = %%a %% 5 if !rest! EQU 2 ( set /a suma = !suma! + %%a set /a numere = !numere! + 1 ) ) if %numere% EQU 0 (echo Media nu se calculeaza) else ( set /a media = %suma% / %numere% echo %media% ) ----------------------------------------------------------------------- 11. e) script.bat 6 7 17 9 1 2 ----------------------------------------------------------------------- @echo off SET /A suma = 0 SET /A pozitie = 0 :start SET /A numar = %1 IF %numar% LSS 6 ( SET /A pozitie = %pozitie% +1 ) if "%~2" NEQ "" ( shift goto :start ) echo %pozitie% ----------------------------------------------------------------------- 11. f) script.bat 4 10 20 30 40 50 60 ----------------------------------------------------------------------- @echo off SET /A p=%1 SHIFT SET /A suma = 0 SET /A pozitie = 1 :start IF %pozitie% LSS %p% ( SET /A pozitie = %pozitie% +1 ) ELSE (goto :checkNumber) if "%~2" NEQ "" ( shift goto :start ) :checkNumber SET /A numar = %1 SET /A divnumber = %numar% / 4 SET /A prodnumber = %divnumber% * 4 SET /A rest = %numar% - %prodnumber% IF %rest% EQU 0 (ECHO E divizibil!) ELSE (ECHO Nu e divizibil!) ----------------------------------------------------------------------- 11 f) varianta de rezolvare 2 @echo off setlocal enabledelayedexpansion SET /A p=%1 SHIFT SET /A pozitie = 0 for %%a in (%*) do ( if !pozitie! NEQ 0 ( echo Elem %%a se afla pe pozitia !pozitie! ) if !pozitie! EQU %p% ( set /a rest = %%a %% 4 if !rest! EQU 0 (echo "Divizibil") else (echo "Nu e divizibil") ) set /a pozitie=!pozitie!+1 ) ----------------------------------------------------------------------- 11 f) varianta de rezolvare 3 @echo off setlocal enabledelayedexpansion SET /p p=p: SET /p n=n: for /L %%a in (1,1,%n%) do ( set /p x=nr[%%a]: if %%a EQU %p% ( set /a rest = !x! %% 4 if !rest! EQU 0 (echo "divizibil") else (echo "nu e divizibil") goto :eof ) )