Thursday, 28 June 2012

c++ program that display following pattern.

for n=5 ;
pattern:
a
a A
a A b
a A b B
a A b B c 



#include <iostream>
using namespace std;

int main()
{
int i,j,k;
char x,z;
//input from user
cout<<"Enter a number ";
cin>>k;

for(i=1;i<=k;i++)
{
x=65;
z=97;
for(j=1;j<=i;j++)
{
if(j%2==0)
{
cout<<x;
x=x+1;



if(x>91)
{
x=65;
}
}
else
{

cout<<z;
z=z+1;
if(z>123)
{
z=97;
}
}
}
cout<<"\n";
}
return 0;
}