 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Program to print Interesting pattern in C++
In this tutorial, we will be discussing a program to print a given interesting pattern.
For this, we will be provided with the half-width of the pattern. Our task is to print a similar pattern according to the given width with its left and right portions being mirror images of one another.
Example
#include<stdio.h> //printing the given pattern void print_pattern(int n){    int i,j;    //printing the upper half    for (i=1; i<=n; i++){       for (j=1; j<=(2*n); j++){          // Left portion          if (i<j)             printf(" ");          else             printf("*");          // Right portion          if (i<=((2*n)-j))             printf(" ");          else             printf("*");       }       printf("\n");    }    //printing the lower half    for (i=1; i<=n; i++){       for (j=1;j<=(2*n);j++){          // Left portion          if (i>(n-j+1))             printf(" ");          else             printf("*");          // Right portion          if ((i+n)>j)             printf(" ");          else             printf("*");       }       printf("\n");    } } int main(){    print_pattern(6);    return 0; }  Output
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Advertisements
 