-
-
Save alphaKAI/3e05347274d86d3ea167 to your computer and use it in GitHub Desktop.
等差数列
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.stdio; | |
| int f(int a, int d, int n){ | |
| return a + d * (n - 1); | |
| } | |
| int sumf(int n, int function(int) fx){ | |
| return n * (fx(1) + fx(n)) / 2; | |
| } | |
| void main(){ | |
| auto fn = ((int n) => f(1, 1, n)); | |
| sumf(10, fn).writeln; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment