#include<iostream>
using namespace std;
void halfPyramidAlphabets1(int n) {
char alphabet = 'a';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cout << alphabet;
}
alphabet++;
cout << endl;
}
}
void halfPyramidAlphabets2(int n) {
char alphabet = 'a';
for (int i = n; i > 0; i--) {
for (int j = 1; j <= i; j++) {
cout << alphabet;
}
cout << endl;
alphabet++;
}
}
void halfPyramidAlphabets3(int n) {
char alphabet = 'a';
for (int i = 1; i <= n; i++) {
for (int k = n - i; k > 0; k--)
cout << " ";
for (int j = 1; j <= i; j++) {
cout << alphabet;
}
cout << endl;
alphabet++;
}
}
void halfPyramidAlphabets4(int n) {
char alphabet = 'a';
for (int i = n; i > 0; i--) {
for (int k = n - i; k > 0; k--)
cout << " ";
for (int j = 1; j <= i; j++) {
cout << alphabet;
}
cout << endl;
alphabet++;
}
}
void halfPyramidAlphabets5(int n) {
for (int i = 1; i <= n; i++) {
char alphabet = 'a';
for (int j = 1; j <= i; j++) {
cout << alphabet++;
}
cout << endl;
}
}
void halfPyramidAlphabets6(int n) {
char alphabet = 'a';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cout << alphabet++;
}
cout << endl;
}
}
int main() {
int num;
cout << "Enter number of levels of the pattern :" << endl;
cin >> num;
halfPyramidAlphabets1(num);
cout << endl;
halfPyramidAlphabets2(num);
cout << endl;
halfPyramidAlphabets3(num);
cout << endl;
halfPyramidAlphabets4(num);
cout << endl;
halfPyramidAlphabets5(num);
cout << endl;
halfPyramidAlphabets6(num);
return 0;
}
70 videos|45 docs|15 tests
|
|
Explore Courses for Software Development exam
|