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);

}

C++ : generate the following figure


            *
 ***
*****
       *******
  *****
  ***
  *

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


#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
static int a=1;
for(int i=1;i<=4;i++)
{
for(int j=0;j<=4-i;j++)
{
cout<<" ";
}
for(int k=1;k<=a;k++)
{
cout<<"*";
}
a=a+2;
cout<<endl;
}


for(int i=3;i>=1;i--)
{
for(int j=1;j<=5-i;j++)
{
cout<<" ";
}

a-=2;
  for(int k=1;k<=a-2;k++)
{
cout<<"*";
}

cout<<endl;
}
getch();
return(0);
}

C++ : generate the following pyramid for n lines


             *
   ***
 *****
*******   (in this pyramid n=4)

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


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;

int main()
{
int n;
cout<<"Enter any number = ";cin>>n;
    static int a=1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=4-i;j++)
{
cout<<" ";
}
for(int k=1;k<=a;k++)
{
cout<<"*";
}
a=a+2;
cout<<endl;
}
getch();
return(0);
}

C++ : generate the pyramid of number as


              1
    121
   12321
  1234321
123454321

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


#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
int i,j,k,l;
for(i=1;i<=5;i++)
{
for(l=1;l<=5-i;l++)
{
cout<<" ";
}
for(j=1;j<=i-1;j++)
{
cout<<j;
}
for(k=i;k>=1;k--)
{
cout<<k;
}
cout<<endl;
}
getch();
return(0);

}

C++ : to design the layout of chess board using nested loop


#include<iostream>
#include<iomanip>
#include<conio.h>

using namespace std;

int main()
{
int i,j,k;
cout<<"Chess board:\n";
cout<<"______________";
cout<<"\n\n";
for(k=0;k<4;k++)
{
        cout<<"\t\t";
        for(i=0;i<4;i++)
    {
        cout<<""<<static_cast<char>(219)<<""<<static_cast<char>(255);
    }
        cout<<endl;
        cout<<"\t\t";
       for(j=0;j<4;j++)
    {
        cout<<""<<static_cast<char>(255)<<""<<static_cast<char>(219);
    }
        cout<<endl;

}
cout<<"\n\n";
getch();

return 0;
}

C++ : generate the following output

* * * * *
* * * *
* * *
* *
*  


#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
int n=5;
for(int i=1;i<=5;i++)
{
for(int j=n;j>=1;j--)
{
cout<<"*";
}
n--;
cout<<"\n";

}
getch();
return(0);
}

C++ : convert binary to decimal


#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<math.h>

using namespace std;

int main()
{
int n,p,b,d=0,i=0;
cout<<"Enter the binary number : ";
cin>>n;
do
{
b=n%10;
if(b==1||b==0)

goto now;
else
{
cout<<"You haven't entered binary no.\n";
cout<<"Try again\n";
getch();
exit(0);
}
 now:
p=b*pow(2,i);
d=d+p;
i++;
n/=10;
}while(n!=0);
cout<<"The num is decimal is "<<d<<endl;
getch();
return(0);
}