using System; namespace Problem2 { class MainClass { public static void Main (string[] args) { int n1,n2,n3,total; n1=1; n2=2; n3=n1+n2; total=2; while (n3<4000000) { if (n3%2==0) total+=n3; n1=n2; n2=n3; n3=n1+n2; } Console.WriteLine ("Sum of even valued terms is {0}",total); } } }
No comments:
Post a Comment