Tuesday, March 23, 2010

Fibonacci

import java.io.*;
public class fibonacci
{  
  public static void main(String args[]) throws IOException
  {  
  InputStreamReader read = new InputStreamReader(System.in);
  BufferedReader br = new BufferedReader(read);
   
  int a=0, b=1;
  int c;
  for(int i=0;i<11;i++)
  { c=a+b;
  System.out.println(c);
  a=b;
  b=c;
  }
  }
}

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. class Fibonacci
    {public static void main(String args[])
    {

    int a=0,b=1,c=0,i;
    System.out.print(a+","+b+",");

    for(i=3;i<=11;i++)
    {
    c=a+b;
    if(i==11)
    System.out.print(c);
    else
    System.out.print(c+",");
    a=b;
    b=c;


    }
    }
    }

    ReplyDelete
  3. to display first 30 terms of the fibonacci series in an array and display the ones which are prime.use a function that checks whether a number is prime or not

    ReplyDelete