Friday, October 21, 2011

Big Integers in C#


Problem 13 in Project Euler(www.projecteuler.net) asks the participant to find the first 10 digits of the sum of fifty 100 digit numbers given. Most the trouble in doing this is finding something that can handle arithmetic on such large numbers. I knew that C# had a data type called BigInteger, which should be able to handle pretty much anything you throw at it. Made this one a Windows Form just for the hell of it. After that it was a simple read in the text file full of numbers into a text box, add them up, and then print out the first ten digits.

You can get the Visual Studio project file here. Contains source code and a runnable .exe:
http://www.sendspace.com/file/mic4n0

SPOILER ALERT: Answer is after the jump.

Answer is: 5537376230

1 comment:

  1. For instance, g-code, the practically universal language of CNC we've at present, did not exist. Each producer was pushing its own language for outlining numerical management or half programs . In order to advertise Bike Helmets extra speedy adoption, the US Army bought one hundred twenty NC machines and loaned them to varied producers so they might turn out to be extra familiar with the thought of numerical management. By the end of the 50’s, NC was starting to catch on, although there have been still a number of|numerous|a selection of} points.

    ReplyDelete