Jump to content

Help me formula for the series

- - - - -

  • Please log in to reply
7 replies to this topic

#1
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Please suggest a formula to sum up the following series
(1+2)/(1*2) + (1+2+3)/(1*2*3) + ........ + (1+2+3+ .... + n)/(1*2*3* .... * n)

i have written the code as follows but there is error in my formula
public class Series

{

public static void main(int n)

{

int i;

double s=0;

for(i=1;i<=n;i++)

s=s+(double)(i+(i+1))/(i*(i+1));

System.out.println("Sum = "+s);

    }

}


#2
Sayan Choudhury

Sayan Choudhury

    Newbie

  • Members
  • Pip
  • 2 posts
Please help me about the above problem. I need it too.

#3
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
I'd create 2 methods. One that computes a summation to n and another that computes the factorial to n.

Then I'd use these in my for loop

For( I to N )
Num += sum(I) / factorial(I);

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
double sum = 1.0;

        double product = 1.0;

        double total = 0.0;


        for (int i = 2; i <= 3; i++) {

            sum += i;

            product *= i;

            total += sum / product;

        }

        System.out.println(total);


#5
Sayan Choudhury

Sayan Choudhury

    Newbie

  • Members
  • Pip
  • 2 posts
Thank you very much doing the problem

here is my complete code
public class Series

{

public static void main(int n)

{

double sum = 1.0;

        double product = 1.0;

        double total = 0.0;


        for (int i = 2; i <= n; i++) {

            sum += i;

            product *= i;

            total += sum / product;

        }

        System.out.println(total);

    }

}





#6
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
deja vu code.

#7
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
what does it mean? "deja vu code"

lethalwire said:

deja vu code.


#8
Sayan

Sayan

    Newbie

  • Members
  • Pip
  • 2 posts
Thank u sir

---------- Post added at 06:17 PM ---------- Previous post was at 06:17 PM ----------

deja vu code ????????????:confused:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users