Author : Rahul
Write a program to calculate the sum of square of n natural numbers.
Program
using System;
namespace ProgrammingQuestion
{
class Program
{
static void Main(string[] args)
{
//Variable Declaration
string numberVal;
int number, result;
//User Input
Console.Write("Enter Number of terms whose square sum needs to be calculated:");
numberVal = Console.ReadLine();
number = Convert.ToInt32(numberVal);
//Square Sum of Natural Number Logic
result = (number * (number + 1) * ((2 * number) + 1)) / 6;
//Print Result
Console.WriteLine($"Square Sum of {number} natural number is: {result}");
Console.Read();
}
}
}
Output
Enter Number of terms whose square sum needs to be calculated:10
Square Sum of 10 natural number is: 385