C++ : generate the following figure


                 ABCDEEDCBA
                 ABCD    DCBA
                 ABC        CBA
                 AB            BA
                 A                A

==================================================


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int i,j,k,l;
for(k=0;k<5;k++)
{
for(i=65;i<=69-k;i++)
{
cout<<static_cast<char>(i);

}
for(l=0;l<2*k;l++)
{
cout<<" ";
}
for(j=69-k;j>=65;j--)
{
cout<<static_cast<char>(j);
}
cout<<endl;
}
getch();
return(0);

}

No comments:

Post a Comment