Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleTesting
- {
- class ConsoleTesting
- {
- static void Main()
- {
- decimal sum = 1;
- decimal precision = 0.001M;
- for (int i = 0, j = 2; i < Int32.MaxValue; i++,j++)
- {
- if (i % 2 != 0)
- {
- decimal temp = (decimal)1 / j;
- if (temp < precision)
- {
- Console.WriteLine(sum.ToString("N3"));
- return;
- }
- else
- {
- sum -= temp;
- }
- }
- else
- {
- decimal temp = (decimal)1 / j;
- if (temp < precision)
- {
- Console.WriteLine(sum.ToString("N3"));
- return;
- }
- else
- {
- sum += temp;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment