write a program in java to 1) print the first 35 terms of the series 1, 1, 2, 3, 5, 8..............…........ 2) print the 52nd term of the above series
Answers
Answered by
1
(1) We need to print first 35 terms of the series 1,1,2,3,5,8.......
class brainly
{
public static void main(String args[])
{
int num1 = 0, num2 = 1, i;
for(i = 0; i<=35;i++)
{
System.out.println(num1);
num1 = num1 + num2;
num2 = num1 - num2;
}
(2) We need to print 52nd term of the series.
import java.util.Scanner;
class brainly
{
public static void main(String args[])
{
int num1 = 0, num2 = 1, n, i, j=1;
System.out.println("Enter the nth term:");
Scanner demo = new Scanner(System.in);
n = demo.nextInt();
if(n == 1)
{
j = 0;
}
else if(n == 2)
{
j = 1;
}
else
{
for(i = 3; i <=n; i++)
{
j = num1 + num2;
num1 = num2;
num2 = j;
}
}
System.out.println("Fibonacci number is :" +j);
}
}
Hope this helps!
class brainly
{
public static void main(String args[])
{
int num1 = 0, num2 = 1, i;
for(i = 0; i<=35;i++)
{
System.out.println(num1);
num1 = num1 + num2;
num2 = num1 - num2;
}
(2) We need to print 52nd term of the series.
import java.util.Scanner;
class brainly
{
public static void main(String args[])
{
int num1 = 0, num2 = 1, n, i, j=1;
System.out.println("Enter the nth term:");
Scanner demo = new Scanner(System.in);
n = demo.nextInt();
if(n == 1)
{
j = 0;
}
else if(n == 2)
{
j = 1;
}
else
{
for(i = 3; i <=n; i++)
{
j = num1 + num2;
num1 = num2;
num2 = j;
}
}
System.out.println("Fibonacci number is :" +j);
}
}
Hope this helps!
siddhartharao77:
:-)
Similar questions