Write a C program to print equilateral triangle star pattern series of n rows. Logic to print pyramid star pattern series in C programming. Learn C programming, Data Structures tutorials, exercises, examples, programs, hacks, tips and tricks online. This section contains Pyramid Programs in C, C Programs to print Star Series, and Different Pattern Printing Programs in C Language. Pattern printing programs contains Star Pattern, Number Pattern and Character Pattern printing.
Problem Statement : Program to Print the Double Pyramid Pattern
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 | inti,j,k; intlines=6; inttemp; k=0; printf('n'); for(j=i;j>=0;j--){ } //step 2 for(j=0;j<blank;j++){ } symbol='F'-(blank/2); if(blank0){ }else{ } for(j=0;j<=temp;j++){//step 4 } } } |
Output :
2 | printf('%c ',symbol--); |
This article is aimed at giving a C++ implementation for pattern printing.
#include <iostream> void pypart( int n) // outer loop to handle number of rows for ( int i=0; i<n; i++) // inner loop to handle number of columns for ( int j=0; j<=i; j++ ) // printing stars } // ending line after each row } int main() int n = 5; return 0; |
Output:
#include <iostream> void pypart2( int n) // number of spaces // n in this case { // inner loop to handle number spaces for ( int j=0; j<k; j++) k = k - 2; // inner loop to handle number of columns for ( int j=0; j<=i; j++ ) // printing stars } // ending line after each row } int main() int n = 5; return 0; |
Output:
#include <iostream> void triangle( int n) // number of spaces // n in this case { // values changing acc. to requirement cout << ' ' ; // decrementing k after each loop // values changing acc. to outer loop { cout << '* ' ; cout << endl; } // Driver Function { triangle(n); } |
Output:
// C++ code to demonstrate printing pattern of numbers using namespace std; // Function to demonstrate printing pattern { int num = 1; // outer loop to handle number of rows for ( int i=0; i<n; i++) // values changing acc. to outer loop cout << num << ' ' ; // incrementing number at each column cout << endl; } // Driver Function { numpat(n); } |
Output:
// C++ code to demonstrate printing pattern of numbers using namespace std; // Function to demonstrate printing pattern { int num = 1; // outer loop to handle number of rows for ( int i=0; i<n; i++) // inner loop to handle number of columns for ( int j=0; j<=i; j++ ) // printing number num = num + 1; cout << endl; } // Driver Function { numpat(n); } |
Output:
// C++ code to demonstrate printing pattern of alphabets using namespace std; // Function to demonstrate printing pattern { // ASCII value // n in this case { // values changing acc. to outer loop { char ch = char (num); // printing char value } // incrementing number cout << endl; } // Driver Function { alphapat(n); } |
Output:
// C++ code to demonstrate printing pattern of alphabets using namespace std; // Function to demonstrate printing pattern { // ASCII value // n in this case { // values changing acc. to outer loop { char ch = char (num); // printing char value num = num + 1; cout << endl; } // Driver Function { contalpha(n); } |
Output:
Printing patterns in python language are discussed in the article below :
This article is contributed by Manjeet Singh(S.Nandini). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.