56.4k views
1 vote
c Write a recursive function called PrintNumPattern() to output the following number pattern.Given a positive integer as input (Ex: 12), subtract another positive integer (Ex: 3) continually until 0 or a negative value is reached, and then continually add the second integer until the first integer is again reached.

User Tim Hardy
by
7.6k points

1 Answer

2 votes

Answer:

def PrintNumPattern(a,b):

print(a)

if (a <= 0): return

PrintNumPattern(a-b,b)

print(a)

PrintNumPattern(12,3)

Step-by-step explanation:

Recursive functions are cool.

User Igor Maznitsa
by
8.2k points