Write a program to print n steps of a Fibonacci series using for loop Code in Java Programming
Write a program to print n steps of a Fibonacci series using for loop Code in Java Programming:
import java.util.*;
class fibonacci
{
public static
void main(String args[])
{
int t,a,b,n;
/* Syntax */ Scanner
scanner name=new Scanner(System.in);
/* Syntax */ System.out.print("Enterd Numberd ");
n=sc.nextInt();
a=1;
b=1;
for(t=0;t<=n;t=a+b)
{
System.out.print(t
+ ",");
a=b;
b=t;
}
}
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment