RosettaCodeData/Task/Jensens-Device/D/jensens-device.d
2023-07-01 13:44:08 -04:00

14 lines
282 B
D

double sum(ref int i, in int lo, in int hi, lazy double term)
pure @safe /*nothrow @nogc*/ {
double result = 0.0;
for (i = lo; i <= hi; i++)
result += term();
return result;
}
void main() {
import std.stdio;
int i;
sum(i, 1, 100, 1.0/i).writeln;
}