This is one of the toughest questions, we discussed in our Programming class. I spent almost 3 hours (or even more than that) to solve the below program. My trainer asked to work on printing the below pattern program.
I wrote in C language. Please go through the program below. As it is mainly dealing with looping statements, you can make use of the same logic in any programming language like Java, C#, etc.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,l,m,z=1,n,o,p,q,r,s,t,u,v,w;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<i;j++)
{
printf(” “);
}
for(k=1;k<=z;k++)
{
printf(“%c”, i+64);
}
for(l=1;l<=9-(2*i);l++)
{
printf(” “);
}
for(m=1;m<=z;m++)
{ if(i==5){ break;}
printf(“%c”, 74-i);
}
for(n=1;n<(2*i)-2;n++)
{
printf(” “);
}
for(o=1;o<=z;o++)
{ if(i==1){break;};
printf(“%c”,i+72);
}
for(p=1;p<=9-(2*i);p++)
{
printf(” “);
}
for(q=1;q<=z;q++)
{ if(i==5){break;}
printf(“%c”,82-i);
}
for(r=1;r<(2*i)-2;r++)
{
printf(” “);
}
for(s=1;s<=z;s++)
{ if(i==1){break;}
printf(“%c”,i+80);
}
for(t=1;t<=9-(2*i);t++)
{
printf(” “);
}
for(u=1;u<=z;u++)
{
if(i==5){break;}
printf(“%c”,90-i);
}
for(v=1;v<(2*i)-2;v++)
{
printf(” “);
}
for(w=1;w<=z;w++)
{ if(i==2){
printf(“%c”,i+88);
}}
printf(“\n”);
}
getch();
}