2016-04-11 60 views
0

我想在Autohotkey中添加一系列连续的奇数(13-1001)。autohotkey:添加连续的数字范围

是否有包含此问题的公式?

这是我有:

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

'z'从哪里来,这个公式与Autohotkey有什么关系? – 2501

+0

我正在回答一系列问题以帮助我了解有关Autohotkey的更多信息。原始问题是:“将所有从13-1001(含)的奇数加到Z”Z来自上一个问题。 Z = 3 – Fafth

+0

你在处理你的例子时遇到了什么问题?显示的代码如何与问题相关?请详细说明。 – 2501

回答

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