- To print full triangle pattern using alphabet
User Input: 3
Output:
A A B A A B C B A
#include <iostream>
using namespace std;
int main() {
int rows;
char c;
cout <<"Enter number of rows: ";
cin >> rows;
for(int i=rows; i>=1; i--) {
c='A';
for(int j=1; j<=(2*rows-i); j++) {
if(j<i)cout<<" ";
else {
if(j<rows)cout<<c++<<" ";
else cout<<c--<<" ";
}
}
cout<<endl;
}
return 0;
}
Enter number of rows: 4 A A B A A B C B A A B C D C B AProgram
Main Logic :
for(int i=rows; i>=1; i--) {
c='A';
for(int j=1; j<=(2*rows-i); j++) {
if(j<i)cout<<" ";
else {
if(j<rows)cout<<c++<<" ";
else cout<<c--<<" ";
}
}
cout<<endl;
}
You can print the same pattern in small alphabets, just set c='a'
Coming Soon !
QuickIn order to succeed you must fail, so that you know what not to do the next time.