我正在尝试在Autohotkey中添加一系列连续的奇数(13-1001)。
是否有一个公式会包含这个问题?
这就是我所拥有的:
a:=13
b:=1001
s1:=((b+1)/2)**2
s2:=((a-1)/2)**2
s:=s1-s2
S3:=z+s
Msgbox,
(
Step 6 Results:
Z is %z%
First # is %a%
Last # is %b%
Sum of consecutive odd numbers (13-1001) is %s%
Z+Sum is %s3%
答案 0 :(得分:0)
此逻辑假设如下:
Start
小于End
Start
和End
都是奇数Start := 13
, End := 1001
, SumOfOddNumbers := (((End + 1)^2)/4) - ((Start - 1)^2)/4))
MsgBox, % "Sum of all odd numbers from " . Start . " to " . End . " is " . SumOfOddNumbers
<强>输出强>
Sum of all odd numbers from 13 to 1001 is 250965
funSumOfOddNumbers( Start, End) {
Temp := (((End + 1)^2)/4) - ((Start - 1)^2)/4))
return, % Temp
} ; end function funSumOfOddNumbers
MsgBox, % "Sum of all odd numbers from 49 to 4009 is " . funSumOfOddNumbers(49, 4009)
<强>输出强>
Sum of all odd numbers from 49 to 4009 is 4019449