0
Write a menu driven program to print 1st 10 Fibonacci series and 1st tribonacci series
4 Respuestas
0
num1=1, num2=2
Sum=num1+num2;
Now , change values for next , like
num1=num2;
num2=sum;
But you are changing values before addition.
And you are printing num1 ,num2 but not printing sum. And only finding single number , not series total.. use a loop to repeat these steps to find series upto a certain n numbers...
Ayush Kumar Singh try these changes and post updated code for any further corrections if any needed..
+ 1
We don't do homework assignments here. Show your attempt first.
0
public class Program
{
public static void main(String[] args)
{
Scanner scnr = new Scanner(System.in);
System.out.println("1 for fibonacci \n 2 for tribonacci ");
Sysyem.out.println("Enter your choice");
int c = scnr.nextint();
switch(c)
{
Case 1:
int num1 = 0;
int num2 = 1;
int sum = 0;
System.out.println("Series is :")
System.out.println(num1+"");
System.out.println(num2+"");
num1=num2;
num2=sum;
sum = num1+num2;
break;
Case 2:
int num3=0;
int num4=0;
int num5=1;
int sum=0;
System.out.println("Series is :");
System.out.println(num3+"");
System.out println(num4+"");
System.out.println(num5+"");
num3=num4;
num4=num5;
num5=sum;
sum = num3+num4+num5;
break;
default;
System.out.println("Wrong choice");
}
}
}
0
See and tell the problem