Advertisement
andruhovski

HomeTask

Oct 23rd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace FileDemo
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] lines = File.ReadAllLines("NUMBERS.TXT");
  15.             foreach (var item in lines)
  16.             {
  17.                 try
  18.                 {
  19.                     double num = double.Parse(item);
  20.                     Console.WriteLine(calc(num));
  21.                 }
  22.                 catch (Exception)
  23.                 {
  24.                     Console.WriteLine("Error in line: {0}",item);
  25.                 }
  26.             }
  27.         }
  28.         public static double calc(double x)
  29.         {
  30.             double s = 0;
  31.             for (int i = 1; i <= 50; i++)
  32.                 s += x / (i * i * i);
  33.             return s;
  34.         }
  35.  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement