Jump to content

Sorry guys, I got nothing this week - behind on my app and didn 't have time to write anything n...


G+_Nate Follmer
 Share

Recommended Posts

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

  • 1 year later...
 Share

×
×
  • Create New...