# Sum of Series-1

/*

Logic:

This problem could be solved by 2 ways:

1.Looping method

2.Formula method

Method 1:

1.Initialize a variable suppose sum to 0.

2.Run a loop for n times.

3.For each iteration add square of iteration no. to sum.

4.Print the result.

Method 2:

1.use the formula: n*(n+1)*(2*n+1)/6

2.Print the result.

*/

Source Code:

#include

int main(){

int n,sum=0,i;

printf("Enter value of nn");

scanf("%d",&n);

//Method 1: Looping

// For each iteration i add i*i to sum

for(i=1;i<=n;i++){
sum+=(i*i);
}
printf("Result acc to method 1: %dn",sum);
//Method 2 : Formula
sum=n*(n+1)*(2*n+1)/6;
printf("Result acc to method 2: %dn",sum);
return 0;
}
[/c]