Number series program (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + ... + (n*n) by parijat

Number series program (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + ... + (n*n) by parijat :


Number series:


using System;

namespace patternProblem.Number
{
    class Number2
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Given series is:");
            Console.WriteLine("(1*1) + (2*2) + (3*3) + (4*4) + (5*5) + ... + (n*n) ");
            Console.WriteLine("----------------------------");
            Console.WriteLine();
            Console.WriteLine("Enter value of n: ");
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();
            int sum = 0;

            Console.WriteLine("-----Output-----");
            Console.WriteLine();
            for (int i = 1; i <= n; i++)
            {
                sum = sum + (i * i);
            }
            Console.WriteLine("Sum of series: " + sum);

            Console.ReadKey();
        }
    }
}

Comments