I write some code.
Program 1
using System;
public class HelloWorld
{
public static void Main(string[] args)
{
long n = 1234567896584256, sum = 0;
for(int i = 1; i <= n; i++)
{
sum += i;
}
Console.WriteLine("Sum "+ sum);
}
}
In this example, this problem has been solved. but it takes more and more time to run it. It is not the right way to solve it because in this program time complexity and space complexity are high.
I write code for this question again.
Program 2
using System;
public class HelloWorld
{
public static void Main(string[] args)
{
long n = 10, sum = 0;
sum = ( n * (n + 1)) / 2;
Console.WriteLine("Sum "+ sum);
}
}
In these answers, all program outputs are the same.