In this post, we will write a C++ program to display patterns of alphabets. the first user will enter the number between 1-19 and then the program will print the pattern of that equivalent character on the output screen.
C++ program to display patterns of alphabets.
#include<iostream>
#include<conio.h>
#include<windows.h>
BOOL gotoxy(const WORD x, const WORD y) {
COORD xy;
xy.X = x;
xy.Y = y;
return SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), xy);
}
int main()
{
system("cls");
int i,j,n;
char ch;
std::cout<<"Enter the number (1-19) you want the alphabets display = ";
std::cin>>n;
for(i=65;i<=65+n;i++)
{
for(j=1;j<=65+n-i;j++)
{
ch = i;
gotoxy(i-64+i-64,j+5);
std::cout<<ch<<std::endl;
}
}
for(i=65+n;i>=65;i--)
for(j=i;j<=65+n-1;j++)
{
ch = i;
gotoxy(65+n-i+65+n-i+(n+n-2), 72-j+(n-2));
std::cout<<ch<<std::endl;
}
getch();
return 0;
}
Output
Enter the number(1-19) you want the alphabet display = 19 A B C D E F G H I J K L M N O P Q R S R Q P O N M L K J I H G F E D C B A A B C D E F G H I J K L M N O P Q R R Q P O N M L K J I H G F E D C B A A B C D E F G H I J K L M N O P Q Q P O N M L K J I H G F E D C B A A B C D E F G H I J K L M N O P P O N M L K J I H G F E D C B A A B C D E F G H I J K L M N O O N M L K J I H G F E D C B A A B C D E F G H I J K L M N N M L K J I H G F E D C B A A B C D E F G H I J K L M M L K J I H G F E D C B A A B C D E F G H I J K L L K J I H G F E D C B A A B C D E F G H I J K K J I H G F E D C B A A B C D E F G H I J J I H G F E D C B A A B C D E F G H I I H G F E D C B A A B C D E F G H H G F E D C B A A B C D E F G G F E D C B A A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A
0 Comments