Problem Description
You just need to calculate the sum of the formula: 1^2+3^2+5^2+……+ n ^2.
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
Problem Description
You just need to calculate the sum of the formula: 1^2+3^2+5^2+……+ n ^2.
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>
#include<math.h>
int main()
{
int i,n;
int sum;
printf("Please input num n:\n");
scanf("%d",&n);
for(i = 1;i <= n;i+=2)
{
sum += pow(i,2);
}
if(sum<pow(2,31))
printf("sum=",sum);
else
printf("The sum is too big!");
return 0;
}