Write the programs in Java to find the sum of the following series: S = 1 + 1 + 2 + 3 + 5 + ...............
Answers
Answered by
4
Answer:
System. out. println(a) ;
System.out.println(b) ;
System. out. println(c);
}
a = b;
b = c;
}
}
Answered by
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