oqis 当前离线
上等兵
评分人数
pcl_test 当前离线
荣誉版主
TOP
DAIC 当前离线
中将
@echo off powershell -c "Get-Content a.txt | Foreach-Object {$s=0}{$s += [Double]($_)}{$s/20}" pause复制代码
amwfjhh 当前离线
六级士官
@if (0)==(0) echo off setlocal enabledelayedexpansion set "strParams=" for /f "delims=" %%i in (1.txt) do set "strParams=!strParams!%%i " echo,传入参数为 %strParams% cscript -nologo -e:jscript %~s0 %strParams% pause & goto :EOF @end var nParmCount; nParamCount = WScript.arguments.length; var fSum=0, fAvg=0; for (var i=0; i<nParamCount; i++) { var fTmp = parseFloat(WScript.arguments(i)); fSum+=fTmp; } fAvg = fSum / nParamCount; WScript.echo(nParamCount + "个数的总和为 : " + fSum + " 平均数为 : " + fAvg);复制代码
terse 当前离线
cat .\b.txt|measure-object -average 复制代码
@if(0)==(0) echo off CScript.exe -NoLogo -E:JScript %0 < "b.txt" pause&exit @end var text = WSH.StdIn.ReadAll().split('\r\n'); var len = text.length; var cnt = 0; for (var i = 0; i < len; i++) { var j = +text[i]; cnt += j; } var avg = cnt / len; WSH.echo(avg)复制代码
回复 terse 啊 一样的情况~~~~~ oqis 发表于 2015-1-12 19:25
yiwuyun 当前离线
四级士官
apang 当前离线
上将
@echo off setlocal enabledelayedexpansion for /f %%a in (a.txt) do ( set "x=%%~xa00" set "x=!x:.=!" set /a "n+=1,Sum+=%%~na00+1!x:~,2!-100" ) set /a Avg=Sum/n echo,!Avg:~,-2!.!Avg:~-2! pause复制代码
回复 terse 要不把小数点都省去,计算出结果,再点上。也可以呀!没影响。 oqis 发表于 2015-1-12 20:13