Computer Science, asked by suhanasubby212, 1 month ago

java program

if on day O, that flower will be having 0 petals. On day 1 and 2,1 and 1 petals respectively.
On day 3, that flower will have 2 petals and on day 4, 3 petals and so on.
On day 7, 13.
Your task is to find out the sum of petals of the flower on day n and to print sum of number_of_petals on
each day till nth day
Ex: given number n, number of days which is non negative integer
consider if day n =10
sum of number if petals will be printed on day 10=0+1+1+2+3+5+8+13+21+34+55=143

Answers

Answered by kajalpal1975
8

Answer:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

int n1 = -1, n2 = 1, term, n, i, sum = 0;

Scanner sc = new Scanner(System.in);

System.out.print("Enter the no. of days : ");

n = sc.nextInt();

for (i = 0; i <= n; i++) {

term = n1 + n2;

sum += term;

n1 = n2;

n2 = term;

}

System.out.println("Sum of no. of petals on day "+n+" will be "+sum);

}

}

Similar questions