In this program, we are going to share a c++ program to print the alphabet triangles. You can print the many different triangles as want like Star triangles, Number triangles, string triangles, etc..
Copy the below code and create a new file named “alphabet-triangles.cpp” and execute it with the help CPP compiler. After executing this program, you will see the output as Alphabet triangles.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <iostream> using namespace std; int main() { char ch='A'; int i, j, k, m; for(i=1;i<=5;i++) { for(j=5;j>=i;j--) cout<<" "; for(k=1;k<=i;k++) cout<<ch++; ch--; for(m=1;m<i;m++) cout<<--ch; cout<<"\n"; ch='A'; } return 0; } |
1 2 3 4 5 |
A ABA ABCBA ABCDCBA ABCDEDCBA |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: arrays, beginners, break, c, c programs, comments, continue, exception, if-else, introduction, object and class, professionals, switch, tutorial