Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env rdmd
- import core.exception;
- import std.stdio;
- import std.conv;
- import std.format;
- void main(string[] args)
- {
- args = args[1..$];
- ulong precision, iterations;
- ulong counter = 1;
- double total = (4.0/counter);
- try
- {
- precision = to!ulong(args[0]);
- }
- catch(RangeError)
- {
- precision = 3;
- }
- try
- {
- iterations = to!ulong(args[1]);
- }
- catch(RangeError)
- {
- iterations = 10000;
- }
- catch(ConvOverflowException)
- {
- writeln("Too many iterations!");
- return;
- }
- for(int iii = 0; iii < iterations; iii++)
- {
- counter += 2;
- total -= (4.0/counter);
- counter += 2;
- total += (4.0/counter);
- }
- writefln("%." ~ to!string(precision) ~ "f", total);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement