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

Recommended Answers

All 5 Replies

Could it be as simple as:

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

?

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

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();
}

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();
}

commented: Don't bump old threads -1

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.