Computer Science, asked by patildhanashri3199, 11 months ago

Write the program to generate the following series where N which is upper limit should be taken as an input.

1, 2, 3,7,16,41,105,274,715…. N

Answers

Answered by parijatsoftwares
0

What is the procedure to print the series 1, 2, 4, 7, …, n in Java?

Hello!!

Well we need to print series 1,2,4,7…n

Logic-

(0+1 =1),( 1+ 1=2),( 2+ 2=4),(4+ 3=7),(7+4=11)…..

Procedure-

Assume a variable add with its initial value 1.

From logic its clear that we need to add previous number with 1,2,3,…

So logic will be add=add+i where I varies from 0 to 13.

For loop is used for executing code(add=add+i) number of times.

Code-

class number

{

Static public void main(String[]args)

{ int add=1;

for (int i=0;i<=13;i++)

{ add=add+i;

System.out.println(add);

}

}

}

HOPE IT HELPS.

PLEASE MARK ME BRAINLIEST

Similar questions