C++ program to find sum of series 1^2+3^2+5^2+……+n^2

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int n,i;
long sum=0;

cout<<“1^2+3^2+5^2+……+n^2nn  Enter Value of n:”;
cin>>n;

for(i=1;i<=n;i+=2)
sum+=(i*i);

cout<<“n Sum of given series is “<<sum;
getch();
}

One thought on “C++ program to find sum of series 1^2+3^2+5^2+……+n^2

  1. Nidhish

    //Here is another way if anyone is interested….It is based on sumation of certain types of series.
    #include
    #include

    void main()
    {
    clrscr();

    int n,sum;
    cout<>n;
    sum = ( ((2 * n) – 1) * (((2 * n) – 1)+ 1) * ( ( 2 * ((2 * n) – 1) ) + 1 ) ) / 6;
    cout<<"The sum is:"<<sum;

    getch();
    }

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *