tom_burgess

PE13

Mar 25th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Numerics;
  8. // requires digits.txt to be in the right place
  9. namespace Euler13
  10. {
  11.     class Program
  12.     {
  13.         static BigInteger sum = 0;
  14.         static void Main(string[] args)
  15.         {
  16.             using (StreamReader read = new StreamReader("C:\\Users\\tombu\\Desktop\\digits.txt")) // load the file into read
  17.             {
  18.                 while (!read.EndOfStream) // scan the fine
  19.                 {
  20.                     string line = read.ReadLine(); // get each line
  21.                     BigInteger num;
  22.                     bool success = BigInteger.TryParse(line, out num); // try to turn it to a big integer and store in num
  23.                     sum += num; // find the sum
  24.                 }
  25.             }
  26.             Console.WriteLine(sum);
  27.             Console.ReadLine();
  28.         } // end of main
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment