16/11/2015

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

Problem :- Write A C++ Program To Find Sum Of Series 1^2+3^2+5^2+ . . . . n^2

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 )

Try Yourself C++ Program To Find Sum Of Series 1+x^1+x^2+x^3+ . . . . . x^n

Solution :-

#include<iostream>
using namespace std;
int main()
{
//By-Ghannedra Yadav
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:-

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

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: