mirror of
https://github.com/dlang-community/dfmt.git
synced 2025-04-25 21:00:03 +03:00
15 lines
274 B
D
15 lines
274 B
D
// Computes average line length for standard input.
|
|
import std.stdio;
|
|
|
|
void main()
|
|
{
|
|
ulong lines = 0;
|
|
double sumLength = 0;
|
|
foreach (line; stdin.byLine())
|
|
{
|
|
++lines;
|
|
sumLength += line.length;
|
|
}
|
|
writeln("Average line length: ",
|
|
lines ? sumLength / lines : 0);
|
|
}
|