G+_Nate Follmer Posted September 11, 2014 Share Posted September 11, 2014 Sorry guys, I got nothing this week - behind on my app and didn't have time to write anything new, but here's the answer to my problem from last week: using System; namespace Fib { class MainClass { public static void Main (string[] args) { long sum = 0; long j = 1; long k = 1; long upperlimit = 4000000000; long evensum = 0; while(j <= upperlimit) { if (j % 2 == 0) { Console.WriteLine (j + " " + "*"); evensum += j; } else { Console.WriteLine (j); } sum=j+k; j=k; k=sum; } Console.WriteLine ("Even Sums = " + evensum); } } } All you had to do was change the variables to types capable of handling bigger numbers. int will max out at 2,147,483,647 - not big enough to hold 4,000,000,000 - A long or a double variable can be used to solve this problem. Just change the upperlimit to a long and leave the rest of the variables at int's... Watch what happens :) Link to comment Share on other sites More sharing options...
G+_Matthew Reardon Posted January 13, 2016 Share Posted January 13, 2016 Nathan: Finally got around to looking at this. Took me a while to realize all the other variables had to have a new type as well. Thanks for your explanations. I used an unsigned integer: https://github.com/highcastle1945/coding101_Nathan_Fibonacci.git Link to comment Share on other sites More sharing options...
Recommended Posts