Computer Science, asked by jaishrijain1977, 9 months ago

write a java program to generate a series
*
*#
*#*
*#*#
*#*#*​

Answers

Answered by lisaRohan
0

Answer:

Hii,

Input : N = 15 K = 5

Output : 15 10 5 0 1 5 10 15

Input : N = 20 K = 6

Output : 20 14 8 2 -4 2 8 14 20

Explanation:

We can do it using recursion idea is that we call the function again and again until N is greater than zero (in every function call we subtract N by K). Once the number becomes negative or zero we start adding K in every function call until the number becomes the original number. Here we use a single function for both addition and subtraction but to switch between addition or subtraction function we used a Boolean flag.

Similar questions