# Print m multiplies of n without using any loop in Python.

PythonProgrammingServer Side Programming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

Given a number n, print m multiplies of n without using any loop. Here we use recursive function.

## Examples

Input: n = 15
Output: 15 10 5 0 5 10 15


## Algorithm

Step 1: Given n.
Step 2: If we are moving back toward the n and we have reached there, then we are done.
Step 3: If we are moving toward 0 or negative.
Step 4: If m is greater, then 5, recursive function with true flag else recursive function is false.
Step 5: If m is not greater than 5 then flag is false.


## Example Code

def printm(p, q, flag):
print(q)
if flag == False and p == q:
return
if flag:
if q - 5 > 0:
printm(p, q - 5, True)
else: # recur with false flag
printm(p, q - 5, False)
else: # If flag is false.
printm(p, q + 5, False)
# Driver Code
n = 15
printm(n, n, True)


## Output

15
10
5
0
5
10
15

Updated on 30-Jul-2019 22:30:23