In this C# program, we will learn how to write a program to generate the sum of N numbers.
Here is the code of the program to generate the sum of N numbers:
using System;
namespace TutorialsrackPrograms
{
class Program
{
//C# Program to Generate the Sum of N Numbers.
static void Main(string[] args)
{
int i, sum = 0, number;
Console.Write("Enter the Nth Number: ");
number = int.Parse(Console.ReadLine());
for (i = 0; i <= number; i++)
{
sum = sum + i;
}
Console.WriteLine("\nSum of N Numbers : " + sum);
Console.Read();
}
}
}
Enter the Nth Number: 50
Sum of N Numbers: 1275
Comments