Computer Science, asked by Anonymous, 1 year ago

WAP to print fibnacci series upto 20 terms

Answers

Answered by Shridhar023
1
class Fibnacci
{
void main()
{
int a=0,b=1,c,count=2;

System.out.print(a+",");

System.out.print(b+",");

while(count!=20)
{
c=a+b;
count++; 
System.out.print(c+",");
a=b;b=c;
}
}
}

This is my first fibnacci program so plz dont be angry If i'm wrong.


Shridhar023: I did this before
Shridhar023: forgot to give space
Shridhar023: rry
Shridhar023: srry
Anonymous: can it be in a more simple manner??
Shridhar023: yes
Shridhar023: i'll try
Anonymous: r u typing???
Shridhar023: import java.util.*;
class armstrong
{
public static void main(String args[])
{
armstrong obj= new armstrong();
int i,n,sum,m;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number : ");
n=sc.nextInt();
m=obj.checknum(n);
if(n==m)
System.out.println("It is a armstrong number");
else
return (int)Math.pow(n%10,3)+ checknum(n/10);
}
}
Shridhar023: import java.io.*;
class prime
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter any no,");
int a = Integer.parseInt(br.readLine());
int fac=0;
for(int i =2;i{
if(a%i==0)
fac=1;
break;
}
if(fac==0)
System.out.println("Prime Number");
else
System.out.println("Not Prime Number");
}
}
Similar questions