

- 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 a pattern without using any loop in C++
In this problem, we are given a number n. Our task is to print patterns with decreasing to 0 or negative then increasing back to the number.
Let’s take an example to understand the problem,
Input: n = 12 Output: 12 7 2 -3 2 7 12
To solve this problem, we will use recursion and call the function after each update. The track of update is kept using the flag variable which tells the function to increase or decrease the number by 5.
Example
The below code gives the implementation of our solution,
#include <iostream> using namespace std; void printNextValue(int m){ if (m > 0){ cout<<m<<'\t'; printNextValue(m - 5); } cout<<m<<'\t'; } int main(){ int n = 13; cout<<"The pattern is:\n"; printNextValue(n); return 0; }
Output
The pattern is − 13 8 3 -2 3 8 13
- Related Questions & Answers
- C program to print number series without using any loop
- Print Number series without using any loop in Python Program
- Python Program for Print Number series without using any loop
- Java Program to print Number series without using any loop
- Print m multiplies of n without using any loop in Python.
- Print first m multiples of n without using any loop in Python
- C Program for Print the pattern by using one loop
- Write a C program to print ‘ABCD’ repeatedly without using loop, recursion and any control structure
- C program to print name inside heart pattern using for loop.
- Print a character n times without using loop, recursion or goto in C++
- How to print a name multiple times without loop statement using C language?
- Print a number 100 times without using loop, recursion and macro expansion in C
- Print “Hello World” without using any header file in C
- Print all substring of a number without any conversion in C++
- Print 1 to 100 in C++, without loop and recursion
Advertisements