Fast test way to sum from 1 to 100000 by using arithmetic series.
public static int Sum(int value)
{
var n = value;
var a1 = 1;
var an = a1 + (n - 1);
var sn = n * (a1 + an) / 2;
return sn;
}
Every Programming Best Practice, Interview Question, Algorithms
Fast test way to sum from 1 to 100000 by using arithmetic series.
public static int Sum(int value)
{
var n = value;
var a1 = 1;
var an = a1 + (n - 1);
var sn = n * (a1 + an) / 2;
return sn;
}
© Best Way to Code 2011 | Design by Blogger Hack Supported by PBT
0 comments:
Post a Comment