Q:

C++ Program To Find Sum Of Given Series 1^2+3^2+5^2+ . . . . n^2

0

Logic :- 

In This series loop initialize with zero and increase by 2 cause we have to find the sum of the power of 2 odd  number so first print odd number then power of 2 after that sum .

 i+=2 ( increase by 2 )
i*i ( Power of 2 )
sum+=(i*i); ( sum of odd )

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;
int main()
{
 int n,i;
 long sum=0;

 cout<<"1^2+3^2+5^2+……+n^2\n\nEnter Value of N :\n";
 cin>>n;

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

 cout<<"\nSum of given series is = "<<sum<<endl;
 return 0;
}

 

Output:

1^2+3^2+5^2+……+n^2

Enter Value of N :

5

Sum of given series is = 35

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program To Print And Find Sum Of Series 1+2+4+... >>
<< C++ Program To Find Sum Of The Given Series 1+x^1+...