C++ PROGRAM of Simple Pyramid Pattern
#include<iostream>
using namespace std;
int main() {
int rows;
cout << "Enter the number of rows: ";
cin >> rows;
for (int i = 1; i <= rows; ++i) {
// Spaces in pyramid
for (int space = 1; space <= rows - i; ++space) {
cout << " ";
}
// Stars in pyramid
for (int j = 1; j <= 2 * i - 1; ++j) {
cout << "* ";
}
cout << endl;
}
return 0;
}
C++ Program of Flipped Simple Pyramid Pattern.
#include<iostream>
using namespace std;
int main() {
int rows;
cout << "Enter the number of rows: ";
cin >> rows;
for (int i = rows; i >= 1; --i) {
// Spaces in pyramid
for (int space = 0; space < rows - i; ++space) {
cout << " ";
}
// Stars in pyramid
for (int j = 1; j <= 2 * i - 1; ++j) {
cout << "* ";
}
cout << endl;
}
return 0;
}
C++ PROGRAM of Inverted Pyramid Pattern
#include<iostream>
using namespace std;
int main() {
int rows;
cout << "Enter the number of rows: ";
cin >> rows;
for (int i = rows; i >= 1; --i) {
// Spaces in inverted pyramid
for (int space = 0; space < rows - i; ++space) {
cout << " ";
}
// Stars in inverted pyramid
for (int j = 1; j <= 2 * i - 1; ++j) {
cout << "* ";
}
cout << endl;
}
return 0;
}
C++ PROGRAM of Triangle Pattern
#include<iostream>
using namespace std;
int main() {
int rows;
cout << "Enter the number of rows: ";
cin >> rows;
for (int i = 1; i <= rows; ++i) {
// Spaces in triangle
for (int space = 1; space <= rows - i; ++space) {
cout << " ";
}
// Stars in triangle
for (int j = 1; j <= i; ++j) {
cout << "* ";
}
cout << endl;
}
return 0;
}
C++ Program of Inverted Triangle Pattern
#include<iostream>
using namespace std;
int main() {
int rows;
cout << "Enter the number of rows: ";
cin >> rows;
for (int i = rows; i >= 1; --i) {
// Spaces in inverted triangle
for (int space = 1; space <= rows - i; ++space) {
cout << " ";
}
// Stars in inverted triangle
for (int j = 1; j <= 2 * i - 1; ++j) {
cout << "*";
}
cout << endl;
}
return 0;
}
C++ Program of Butterfly Pattern
#include<iostream>
using namespace std;
int main() {
int n;
cout << "Enter the number of rows for the butterfly pattern: ";
cin >> n;
// Upper part of butterfly
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
cout << "* ";
}
int spaces = 2 * (n - i);
for (int j = 1; j <= spaces; ++j) {
cout << " ";
}
for (int j = 1; j <= i; ++j) {
cout << "* ";
}
cout << endl;
}
// Lower part of butterfly
for (int i = n; i >= 1; --i) {
for (int j = 1; j <= i; ++j) {
cout << "* ";
}
int spaces = 2 * (n - i);
for (int j = 1; j <= spaces; ++j) {
cout << " ";
}
for (int j = 1; j <= i; ++j) {
cout << "* ";
}
cout << endl;
}
return 0;
}
C++ Program of Number Pyramid Pattern
#include<iostream>
using namespace std;
int main() {
int rows;
cout << "Enter the number of rows: ";
cin >> rows;
for (int i = 1; i <= rows; ++i) {
// Spaces in pyramid
for (int space = 1; space <= rows - i; ++space) {
cout << " ";
}
// Numbers in pyramid
for (int j = 1; j <= i; ++j) {
cout << j << " ";
}
cout << endl;
}
return 0;
}
C++ Program of Continuous Number Pyramid
#include<iostream>
using namespace std;
int main() {
int rows, count = 0;
cout << "Enter the number of rows: ";
cin >> rows;
for (int i = 1; i <= rows; ++i) {
// Spaces in pyramid
for (int space = 1; space <= rows - i; ++space) {
cout << " ";
}
// Numbers in pyramid
for (int j = 1; j <= i; ++j) {
cout << ++count << " ";
}
cout << endl;
}
return 0;
}
C++ Program of Palindrome Triangle Pattern
#include<iostream>
using namespace std;
int main() {
int rows;
cout << "Enter the number of rows: ";
cin >> rows;
for (int i = 1; i <= rows; ++i) {
int num = 1;
// Spaces
for (int space = 1; space <= rows - i; ++space) {
cout << " ";
}
// Left side
for (int j = 1; j <= i; ++j) {
cout << num++;
}
// Right side
for (int k = i - 1; k >= 1; --k) {
cout << k;
}
cout << endl;
}
return 0;
}
C++ program that prints your name in a pyramid pattern
#include<iostream>
#include<string>
using namespace std;
int main() {
string name;
cout << "Enter your name: ";
getline(cin, name);
int length = name.length();
// Printing pyramid pattern
for (int i = 0; i < length; ++i) {
// Printing spaces
for (int j = 0; j < length - i - 1; ++j) {
cout << " ";
}
// Printing characters of name
for (int j = 0; j <= i; ++j) {
cout << name[j] << " ";
}
cout << endl;
}
return 0;
}