1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /*Write a program to find Fibonacci series of a given no. Example : Input - 8 Output - 1 1 2 3 5 8 13 21 */ class Fibonacci{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); //taking no. as command line argument. System.out.println("*****Fibonacci Series*****"); int f1, f2=0, f3=1; for(int i=1;i<=num;i++){ System.out.print(" "+f3+" "); f1 = f2; f2 = f3; f3 = f1 + f2; } } } |
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Resources #Terms of Use
Copyright©2012 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com
thank u………………..it was a nice help
can you help me how to solve this problem??its also a fibonacci series
example input:
first number = 3
second number = 5
terms = 5
output:
3, 8, 13, 21, 34,
thank uuuuuuuuuu
how to write a java program of sorting a number with in afile?
you have to improove your proper word in program…
u jaffa prog was not excuting…………. maintain good contents
Thank u so much……its very simple to learn us….
help me write a program dat will generate this fibonacci series 1,1,2,3,5,8,13
thanks.
thnq so much…………..
import java.util.Scanner;
public class series
{
public static void main (String[]args){
Scanner in = new Scanner (System.in);
System.out.println(“Type in the number of terms”);
int n = in.nextInt();
if (n == 1)
{
System.out.println(“1″);
return;
}
if (n == 2)
{
System.out.println(“1 1″);
return;
}
int res = 1 ;
int fnum = 1;
System.out.print(“1 1 “);
for (int i = 1 ; i<=n ; i++){
int temp = res;
res = fnum;
fnum = res + temp;
System.out.print(fnum + " ");
}
}
}
How do i convert this into buffered reader ??
Thank u so much……..it was easy to learn,for java programming.once again thank u so much…………..
thnx….
anne says:
December 8, 2011 at 3:01 pm
can you help me how to solve this problem??its also a fibonacciseries
example input:
first number = 3
second number = 5
terms = 5
output:
3, 5,8, 13, 21, 34,
import java.io.*;
class fibonacci
{
public static void main(String args[])
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println(“ENTER VALUE OF n:”);
int n=Integer.parseInt(dis.readLine());
int f1,f2,f3;
f1=3;
f2=5;
System.out.println(f1 “\t” f2 “\t”);
for(int i=2;i<=n;i )
{
f3=f1 f2;
System.out.println(f3 "\t");
}
f1=f2;
f2=f3;
}
}
0,1,1,2,3,5,8…144
how cn we convert this ??
very useful!!
thank u so much…
Thnks a lot:)
Input Format:
The input consists of a single integer which corresponds to ‘n’
Output Format:
Output consists of a single integer which corresponds to the the nth flibonakki number.
Sample Input:
plss send me fibbnoci program to the above description
Try this way also:
class FibbbSeriesssprevious3
{
public void input(int n)
{
System.out.print(0+”,”+1);
int a=0,i=1,p=0;
while(i<n)
{
a=a+i+p;
if(a<=n)
System.out.print(","+a);
i=i+a+p;
if(i<=n)
System.out.print(","+i);
p=i+p;
if(p<=n)
System.out.print(","+p);
}}}
Sorry I posted a wrong program,
this is the correct one:
class FibbbSeriesssprevious2
{
public void input(int n)
{
int a=0,i=1;
while(a<n)
{
if(a<=n)
System.out.print(a+",");
a=a+i;
if(i<=n)
System.out.print(i+",");
i=i+a;
}}}
public class Fibonacci{
public static void main(String args[]){
int a=0;
int b=1;
int temp=0;
for(int i=1; i<=15; i++){
System.out.println(temp+"="+"fibonacci");
a=b;
b=temp;
temp=a+b;
}
}
}
help me write a program dat will generate this fibonacci series 1,1,2,3,5,8,13
public class Fibonacci
{
public static void main(String args[])
{
int i=0;
int j=1;
int num=0;
for(int a=0; a<=7; a++)
{
System.out.print(num+" ");
i=j;
j=num;
num=i+j;
}
}
}
import java.lang.*;
import java.util.*;
class One
{
public static void main(String args[])
{
int [] num={12,25,47,85,45,58,56,55,89,81,2,78};
Arrays.sort(num);
for(int k[].num);
System.out.println(k);
}
}
this program is used to sort elements.
import java.lang.*;
import java.util.*;
class One
{
public static void main(String args[])
{
int [] num={12,25,47,85,45,58,56,55,89,81,2,78};
Arrays.sort(num);
System.out.println(Arrays.toString(num));
}
}
import java.lang.*;
import java.util.*;
class Two
{
public static void main(String args[])
{
int prev,next,sum,n;
prev=next=1;
for(n=0;n<=10;n++)
{
System.out.println(prev);
sum=prev+next;
prev=next;
next=sum;
}
}
}
this program is used to print 1,1,2,3,5,8,13….
this code not enough to print the sreies like 011235…….
public class fib2
{
public static void main(String[] args)
{
int maxIndex = 20, fnum = 0, snum = 1, tnum;
for(int i = 0; i < maxIndex; i++)
{
System.out.println(fnum);
tnum = snum+fnum;
fnum = snum;
snum = tnum;
tnum = snum;
}
}
}
Here’s a simplified version. Cheers
import java.util.*;
class fib3
{
public static void main(String[] args)
{
System.out.println(“Enter fibonacci number: “);
Scanner scan = new Scanner(System.in);
int input = scan.nextInt();
int fnum = 0, snum = 1, subsequent;
for(int i = 0; i<input; i++)
{
System.out.println(fnum);
subsequent = fnum + snum;
fnum = snum;
snum = subsequent;
}
}
}
Himachal Pradesh