【Project Euler】6 第六题



//The sum of the squares of the first ten natural numbers is,
        //12 + 22 + ... + 102 = 385
        //The square of the sum of the first ten natural numbers is,
        //(1 + 2 + ... + 10)2 = 552 = 3025
        //Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
        //Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
       

static void Main(string[] args)
        {
            int num1 = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;
            for (int i = 1; i < 101; i++)
            {
                num1 += i * i;
                num2 += i;

            }
            num3 = num2 * num2;
            num4 = num3 - num1;
            Console.WriteLine(num1);
            Console.WriteLine(num3);
            Console.WriteLine(num4);
        }

版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

原文地址:https://www.cnblogs.com/NoMasp/p/4786196.html