0

Write a menu driven program to print 1st 10 Fibonacci series and 1st tribonacci series

7th Mar 2021, 9:50 AM
Ayush Kumar Singh
4 Respostas
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..
7th Mar 2021, 10:08 AM
Jayakrishna 🇮🇳
+ 1
We don't do homework assignments here. Show your attempt first.
7th Mar 2021, 9:52 AM
Artem 🇺🇦
Artem 🇺🇦 - avatar
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"); } } }
7th Mar 2021, 9:52 AM
Ayush Kumar Singh
0
See and tell the problem
7th Mar 2021, 9:53 AM
Ayush Kumar Singh