Pattern 2
AAAAA
BBBB
CCC
DD
E
Code
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int i,j,rows;
rows=4;
for(i=1; i<=rows; i++){
for(j=i; j<=rows; j++){
cout<<((char)(i+64));
}
cout<< endl;
}
getch();
return 0;
}
Output
AAAA
BBB
CC
D
Pattern 3
A
AB
ABC
ABCD
ABCDE
Code
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int i,j,rows;
rows=3;
for(i=1; i<=rows; i++){
for(j=1; j<=i; j++){
cout<<((char)(j+64));
}
cout<< endl;
}
getch();
return 0;
}
Output
A
AB
ABC
Try and compile by yourself with the help of online C++ Compiler for better understanding.
Pattern 4
A
BA
CBA
DCBA
EDCBA
Code
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int i,j,rows;
rows=6;
for(i=1; i<=rows; i++){
for(j=i; j>=1; j--){
cout<<((char)(j-1+65));
}
cout<<"\n";
}
getch();
return 0;
}
Output
A
BA
CBA
DCBA
EDCBA
FEDCBA
Also check out this article - Pair in C++
FAQs
-
How to check an alphabet in C++?
ASCII values of capital letters range from 65 to 90, and that of small letters range from 97 to 122. So if the integer value of the entered character ranges from 65 to 90 or 97 to 122, then it is an alphabet; otherwise, it is not.
-
What is the ASCII value range of alphabets?
ASCII values of capital letters range from 65 to 90, and that of small letters range from 97 to 122.
Key Takeaways
In this blog, we learnt about the approaches to different alphabet triangle patterns and wrote the codes for the same using C++ language. We hope that this blog has helped you enhance your knowledge, and if you wish to learn more, check out our Coding Ninjas Blog site and visit our Library. Do upvote our blog to help other ninjas grow.
Recommended Readings:
Happy Learning!