Uva 10579 – Fibonacci Numbers

Problem:- http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1520

Solution :-

java code:

import java.math.BigInteger;
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
      Scanner in = new Scanner (System.in);
      int n;
      while(in.hasNext())
      {
          n=in.nextInt();
          BigInteger a=BigInteger.ONE;
          BigInteger b=BigInteger.ONE;
          BigInteger sum=BigInteger.ZERO;
          while(n>=3)
          {
              sum=a.add(b);
              b=a;
              a=sum;
              n–;
          }
       System.out.println(sum);
      }
    }

}

At First you can try to solve this problem if you can’t than see this code & find what’s your problem . If you copy paste this code you could not improve yourself in programming .

Posted by Shipu Ahamed

Leave a Reply