954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

sum of series

Can smeone help me to write a prog. to find the sum of the following series:
1+(1+2)+(1+2+3)+....... n terms

Regds.
TEJAS

Tejas
Newbie Poster
6 posts since Jun 2004
Reputation Points: 11
Solved Threads: 0
 

Could it be as simple as:

series = 0;
for (int i = 1; i <= n; i++) 
    for (int j = 1; j <= i; j++
        series += i;

?

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

Hello,

I seem to remember from math somewhere that there is a formula out there for this, to save the iterations. Might want to Google search it out.

Christian

kc0arf
Posting Virtuoso
Team Colleague
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
 

Chainsaw's code is correct except for one thing, you add j to the sum, not i;

#include
#include

void main()
{
int n;
cin>>n;
int i, j;
int sum=0;
for (i=1; i<=n; i++)
{
for (j=1; j<=i; j++)
{
sum+=j;
}
}
cout<

iamboredguy
Newbie Poster
23 posts since Aug 2004
Reputation Points: 12
Solved Threads: 0
 

hello friends...i want to write code for series 1/1!+2/2!+....n/n!

i have written d code but it prints sum 2 always...

pl chk my code

nd post d correct one

is there enyway to do it with a single loop but without using arrays..

here u go wid code

//wap to find sum of series and print series also

#include
#include
void main()
{
clrscr();
int n,x,temp;
float sum=0;
cout<<"enter nth term till which u want to compute";
cin>>n;
for(int i=1;i<=n;i++)
{
int x=1;
for(int j=i;j>1;j--)
{
x=x*j;
}
float temp=i/x;
sum+=temp;
cout<

angelrapunzel
Newbie Poster
3 posts since Jun 2010
Reputation Points: 9
Solved Threads: 0
 

can anyone help me with d logic of series x^1+x^2-x^3+x^4-x^5....

angelrapunzel
Newbie Poster
3 posts since Jun 2010
Reputation Points: 9
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You