Write a c program to find out the sum of series 1^2 + 2^2 + …. + n^2.


Sum of 1^2 + 2^2 + …. + n^2 series in c programming language

#include<stdio.h>

int main(){

    int n,i;
    int sum=0;

    printf("Enter the n i.e. max values of series: ");
    scanf("%d",&n);

    sum = (n * (n + 1) * (2 * n + 1 )) / 6;

    printf("Sum of the series : ");

    for(i =1;i<=n;i++){
         if (i != n)
             printf("%d^2 + ",i);
         else
             printf("%d^2 = %d ",i,sum);
    }

    return 0;
}

Sample output:

Enter the n i.e. max values of series: 5
Sum of the series: 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 55

Mathematical Formula:

Sum of the series 12 + 22 + 32 + … + n2 =
n (n+1) (2n+1)/6

6. Write a c program to find out the sum of given H.P.

20 comments:

preeree said...

thanks...............

Anonymous said...

Help me
Write a C or Java program to find out the sum of series:
1! + 2! + 3! + . . . + N, with N input from keyboard

Md Faiyaz Ansari said...

thank you :)

Anonymous said...

1/x+1/x^2+1/x^3+.....

Ah Lop said...

Very good..

Vibon Keat said...

Dear sir, Can you have me to write total sum of 2^2+10^2+20^2+50^2+100^2 in java??

mohsinahmed alif said...

1^2+3^2+5^2....................nth find out sum use for loop in c

mohsinahmed alif said...

plz........ any one help me.........

monir hossain said...

#include
int main()
{
int n,sum=0,i;
printf("Please Enter Number:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
sum=(sum+i*i);
}
printf("%d",sum);
return 0;
}

eng porag said...

please solutionthis program in C++ to generate the series as 1, 3, 4, 8, 15, 27, 50, ........

eng porag said...

please solution this program in C++ to generate the series as 1, 3, 4, 8, 15, 27, 50, ........

Solaiman Shohag said...

#include
int main()
{
int n,sum=0,i;
printf("Please Enter Number:");
scanf("%d",&n);
for(i=1;i<=n;i=i+2)
{
sum=(sum+i*i);
}
printf("%d",sum);
return 0;
}

Tapos Bormon said...

1^2+2^4+3^6+4^8+.............+n^2n for loop c programming code please ans me

Abhra Mitra,1997 said...
This comment has been removed by the author.
Abhra Mitra,1997 said...

your program didn't work. I did a little modification and now it works..

#include
int main()
{
int n,sum=1,i, j=0;
printf("Please Enter Number:");
scanf("%d",&n);
for(i=1;i<=n; i++)
{
sum=(sum+(j*j));
j=j+2;
}
printf("%d",sum);
return 0;
}

Cynthia Zemp said...
This comment has been removed by the author.
jonatha ivan sanchez martinez said...

1^2+2^2+n^2 /n^2 en c++ como quedaría me dijeron que fuera dando los pasos

jonatha ivan sanchez martinez said...

que libreria metiste para que funcionara el programa

Tewfiqur Rahman said...

please help me with this series c programing

2^2+4^4+......n^n

Avi Singh said...

can u help me to write a program in c to print the series
2, 6, 11, 10, 15, 21, 18, 24, 31, 26, 33, 41 .....answer me as much as possibel