There are various types of triangles that can be displayed, including those formed using letters or digits. This C++ code will focus on generating triangles using alphabets.
Let's explore a C++ illustration demonstrating how to display an alphabet triangle.
Example
Example
#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;
}
Output:
Output
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA