C# program to find Sum of first n Even Natural Numbers
Program
using System;
namespace SumOfNEvenNumbers
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the value of n:\t");
int n = int.Parse(Console.ReadLine());
int i, evenSum = 0;
for(i = 1; i <= n; i++)
{
if((i % 2) == 0)
{
evenSum += i;
}
}
Console.WriteLine("Sum of even numbers from 1 to {0} is {1}\t", n, evenSum);
}
}
}
Output
Enter the value of n: 15
Sum of even numbers from 1 to 15 is 56