CPP program to print Alphabet Triangle

The below program is to print the Alphabet Triangle in CPP using loop.

Code:

#include <iostream.h>
using namespace std;
 
int main()
{  
char ch='a';    
int i, j, k, l;    
for(i=1;i<=5;i++)    
{    
for(j=5;j>=i;j--)    
cout<< " ";    
for(k=1;k<=i;k++)    
cout << ch++;    
ch--;    
for(l=1;l<i;l++)    
cout<<--ch;    
cout<< "\n";    
ch='a';    
}    
return 0;
}

Output

       a
      aba
     abcba
    abcdcba
   abcdedcba
Please follow and like us:
Content Protection by DMCA.com