Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
where is the problem?

C#
package fibonatchi;
class Main{
    public static void Main(String[]args){
System.out.printf("Wich Fibonacci Number do you want?");
//System.out.scanf("%d", &inp);
int fib1 = 1;
int fib2 = 0;
switch(fib)
 {
 case 0:
 System.out.printf(" Sorry, no result for f(0)");
   break;
 case 1:
 System.out.printf(" Fib(1) = 0");
   break;
 case 2:
   System.out.printf(" Fib(1) = 0");
   System.out.printf(" Fib(2) = 1");
   break;
 default:
   System.out.printf(" Fib(1) = 0");
   System.out.printf("Fib(2) = 1");
   for (int i=1; i<= fib -2; ++i)
    {
    fib = fib1 + fib2;
    fib2 = fib1;
    fib1 = fib;
      System.out.printf("Fib(%d) = %d", i + 2, fib);
    }
 }
}
}
Posted
Updated 24-Jan-10 5:43am
v3

what output you are getting by this ?

Also what is the requirement of this section ?

mf_arian wrote:
switch(fib)
{
case 0:
System.out.printf(" Sorry, no result for f(0)");
break;
case 1:
System.out.printf(" Fib(1) = 0");
break;
case 2:
System.out.printf(" Fib(1) = 0");
System.out.printf(" Fib(2) = 1");
break;
default:


Actually you are setting fib = 0 and then using switch block, so every time the program enters the switch it will print Sorry, no result for f(0)
and exit.

So the issue is with the switch. :rose:
 
Share this answer
 
Variable fib is not defined anywhere so this code does not even compile. Perhaps you should review your algorithm.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900