autohotkey:添加连续的数字范围

时间:2016-04-11 18:38:13

标签: math range autohotkey addition

我正在尝试在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%

1 个答案:

答案 0 :(得分:0)

转发

此逻辑假设如下:

  • Start小于End
  • StartEnd都是奇数

原始示例

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