

- 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 the given pattern recursively
Here, as per the given problem pattern needs to be displayed using recursive approach.
Recursive function is the one that calls itself n number of times. There can be ‘n’ number of recursive function in a program. The problem working with recursive function is their complexity.
Algorithm
START Step 1 -> function int printpattern(int n) If n>0 Printpattern(n-1) Print * End IF End Step 2 -> function int pattern(int n) If n>0 pattern(n-1) End IF Printpattern(n) Print \n End STOP
Example
#include <stdio.h> int printpattern(int n) { if(n>0) { printpattern(n-1); printf("*"); } } int pattern(int n) { if(n>0) { pattern(n-1); //will recursively print the pattern } printpattern(n); //will reduce the n recursively. printf("\n"); //for new line } int main(int argc, char const *argv[]) { int n = 7; pattern(n); return 0; }
Output
if we run above program then it will generate following output.
* ** *** **** ***** ****** *******
- Related Questions & Answers
- Java program to print a given pattern. (stars)
- Java Program to Print a Square Pattern for given integer
- PHP program to print the number pattern
- Print lower triangular matrix pattern from given array in C Program.
- Print matrix in diagonal pattern
- How to print pattern in Python?
- Python Program to print the pattern ‘G’
- Java Program to Print the Left Triangle Star Pattern
- Program to print Interesting pattern in C++
- Program to print Kite Pattern in C++
- Program to print number pattern in C
- Program to print Diamond Pattern in C
- Program to print numeric pattern in C
- Program to print pyramid pattern in C
- Java Program to Print Pyramid Star Pattern
Advertisements