Computer Science, asked by meeradevikanojia1973, 1 month ago

4. Write a program in Java to find the sum of the given series:[15]
a) 1 + 1/2 + 1/3 + ... + 1/20
b) Generate and display the first 10 terms of the Fibonacci series,​

Answers

Answered by pratikbagadiya29
0

Answer:

a) sum of 1+1/2+...+1/20 = 3.59

b) Fibonacci series = 0,1,1,2,3,5,8,13,21,34

Explanation:

Explanation of a) :

double a=1,b=20,sum=0;

       while(a<=b)

       {

           sum += (1/a);

           a++;

       }  

       System.out.println("Sum = "+sum);

Explanation of b) :

int i=1,a=0,b=1,sum=0;

       while(i<=10)

       {

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

           sum=a+b;

           a=b;

           b=sum;

           i++;

       }

Similar questions