Computer Science, asked by amarjeetmurmu, 10 months ago

Write the programs in Java to find the sum of the following series: S = 1 + 1 + 2 + 3 + 5 + ...............​

Answers

Answered by Anonymous
4

Answer:

class \: series \\ \:   \:  \\

{

public \: static \: void \: main(int \: n)

{

int \: a = 0; \\ </p><p>int  \: b=1;

System. out. println(a) ;

System.out.println(b) ;

for(int \: c = a + b;c&lt;=n;c=a+b)

{

System. out. println(c);

}

a = b;

b = c;

}

}

Answered by akshat78952
0

Answer:

import java.util.Scanner;

public class KboatSeries

{

   public void computeSeriesSum() {

       

       Scanner in = new Scanner(System.in);

       System.out.print("Enter n: ");

       int n = in.nextInt();

       

       int a = 1, b = 1;

       int sum = a + b;

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

           int term = a + b;

           sum += term;

           a = b;

           b = term;

       }

       

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

   }

   

   

   

}

Explanation:

Similar questions