
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print m multiplies of n without using any loop in Python.
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
- Related Questions & Answers
- Print first m multiples of n without using any loop in Python
- Print Number series without using any loop in Python Program
- Python Program for Print Number series without using any loop
- Print a pattern without using any loop in C++
- Java Program to print Number series without using any loop
- C program to print number series without using any loop
- Print a character n times without using loop, recursion or goto in C++
- Print first m multiples of n in C#
- Write a C program to print ‘ABCD’ repeatedly without using loop, recursion and any control structure
- Python Program to Print Numbers in a Range (1,upper) Without Using any Loops
- Program to print numbers from 1 to 100 without using loop
- Print “Hello World” without using any header file in C
- Print all substring of a number without any conversion in C++
- Printing all subsets of {1,2,3,…n} without using array or loop in C program
- Find a positive number M such that gcd(N^M,N&M) is maximum in Python
Advertisements