C++ Program to draw alphabets triangle from A to E

C-Plus-Plus-Programs

This post is about C++ Program to draw alphabets triangle from A to E. We will code for upper case alphabets and lower case alphabets.

A
A B
A B C
A B C D
A B C D E

C++ Program to draw triangle of alphabets


To draw a triangle in c++ we need ASCII code of characters A to E.In this example, we are drawing a triangle of the Upper case letter.

CharacterASCII Value
A65
B66
C67
D68
E69

How does it work


The ASCII values for A to E are given in the above Table.We have used the outer loop for loop for(i=65;i<=69;i++) start from ASCII value of A to E mean(65 to 69).

And the inner loop will also start from 65 and its value remains less than and equal to the value of the variable I

By using the (char) we are converting ASCII value to the character.

We are printing the char to draw a Triangle. The newline character (\n) to add a new line.

#include <iostream>
using namespace std;
int main()
{
int i,j;
for(i=65;i<=69;i++)
{
for(j=65;j<=i;j++)
{
cout<<(char)j<<"\t";
}
cout<<"\n";
}
return 0;
}

Output

A
A B
A B C
A B C D
A B C D E

C++ Program to draw triangle of lower case letter a to e


In this example, we will do code for how to draw a triangle of lower case letters from a to E.

CharacterASCII Value
a97
b98
c99
d100
e101

How does it work


The ASCII values for A to E are given in the above Table.We have used the outer loop for(i=97;i<=101;i++) start from ASCII value of A to E mean(65 to 69).

And the inner loop will also start from 97 and its value remains less than and equal to the value of the variable I

By using the (char) we are converting ASCII value to the character.

We are printing the char to draw a Triangle. The newline character (\n) to add a new line.

#include <iostream>
using namespace std;
int main()
{
int i,j;

 
for(i=97;i<=101;i++)
{
for(j=97;j<=i;j++)
{
cout<<(char)j<<"\t";
}
cout<<"\n";
}
return 0;
}

Output

a	

a	b	

a	b	c	

a	b	c	d	

a	b	c	d	e