0

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

5
Contributors
5
Replies
6
Views
13 Years
Discussion Span
Last Post by angelrapunzel
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;

?

0

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

0

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

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

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<<sum<<'\n';
getch();
}

-3

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<iostream.h>
#include<conio.h>
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<<i<<"/"<<x<<"+";
}


cout<<"sum of series is"<<sum;
getch();
}

Votes + Comments
Don't bump old threads
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.