Marshal's confusion

Marshal’s confusion

one day, Marshal want to show the answer : 12+32+5^2+……+ n ^2.
please tell to him.

Input
In each case, there is an odd positive integer n.

Output
Print the sum. Make sure the sum will not exceed 2^31-1

Sample Input

3

Sample Output

10
#include <stdio.h>
int main(void)
{
    long n;
    while(scanf("%ld", &n) == 1)
    {
        long sum = 0;
        for(int i = 1; i <= n; i += 2)
        {
            sum += pow(i, 2);
        }
        printf("%ld\n", sum);
    }
}

pow(a,b):a^b

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章