Compute 1 + 2 + … + 6.
Ready — edit the code above and click Run.
using System;
class Program
{
static void Main()
{
int n = 6;
Console.WriteLine(n * (n + 1) / 2);
}
}
Try solving on your own first, then reveal the official answer.
Gauss formula or loop.