create a method that calculate cumulative sum chart for 20 points in csharp

Here's a method in C# that takes an array of 20 integers and returns their cumulative sum chart:

main.cs
public static int[] GetCumulativeSumChart(int[] values)
{
    int[] chart = new int[values.Length];

    int sum = 0;
    for (int i = 0; i < values.Length; i++)
    {
        sum += values[i];
        chart[i] = sum;
    }

    return chart;
}
245 chars
14 lines

To use this method, you would create an array of 20 integers, call the method with the array as the argument, and then do something with the returned cumulative sum chart:

main.cs
int[] values = new int[] { 3, 5, 7, 2, 1, 5, 8, 2, 4, 6, 7, 9, 1, 4, 6, 2, 3, 5, 7, 8 };

int[] chart = GetCumulativeSumChart(values);

foreach (int value in chart)
{
    Console.WriteLine(value);
}
199 chars
9 lines

This would output the following cumulative sum chart:

main.cs
3
8
15
17
18
23
31
33
37
43
50
59
60
64
70
72
75
80
87
95
58 chars
21 lines

gistlibby LogSnag