C++ Program to Print Alphabet Triangle
There are different triangles that can be printed. Triangles can be generated by alphabets or numbers. In this C++ program, we are going to print alphabet triangles.
Let's see the C++ example to print alphabet triangle.
- #include iostreamm.h>
- #include <conio.h>
- void 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';
- }
- getch ();
- }
Output:
A ABA ABCBA ABCDCBA ABCDEDCBA
0 Comments