prg to display diamond and pascals triangle

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,i,f,r,b,g,c,h,v=1,q,j,n,p,k=1;
int ch;
cout<<“Enter choice 1:STARS”<<endl;
cout<<” 2:NUMBERS”<<endl;
cin>>ch;
switch(ch)
{
//WITH STAR
case 1:
v=2;
char a2[100][100];
cout<<“Enter Limit : “<<endl;
cin>>n;
p=n-1;
//INPUTTING
for(i=0;i<=(2*n)-2;i++)
{
for(j=0;j<=(2*n)-2;j++)
{
a2[i][j]= ‘ ‘;
}
}
//STARTING
for(i=0;i<=(2*n)-2;i++)
{
for(j=0;j<=(2*n)-2;j++)
{
if(((i+j)==p)&&(i<n))
{
for(c=0;c<k;c++)
{
a2[i][j]=’*’;
j=j+v;
}
k++;
j=(2*n)-2;
r=c-1;
}
if(((i+j)==(p+2))&&(i>=n))
{
for(h=r;h>0;h–)
{
a2[i][j]=’*’;
j=j+v;
}
p=p+2;
r–;
j=(2*n)-2;
}
}
}
for(i=0;i<=(2*n)-2;i++)
{
cout<<endl;
for(j=0;j<=(2*n)-2;j++)
{
cout<<a2[i][j];
}
}
break;

//CASE TWO WITH NUMBERS
case 2:
int a[100][100];
cout<<“Enter Limit : “<<endl;
cin>>n;
p=n-1;
for(i=0;i<=(2*n)-2;i++)
{
for(j=0;j<=(2*n)-2;j++)
{
a[i][j]=0;
}
}
for(i=0;i<=(2*n)-2;i++)
{
for(j=0;j<=(2*n)-2;j++)
{
if(((i+j)==p)&&(i<n))
{
b=1;
for(c=0;c<k;c++)
{
if(j<=(n-1))
{
a[i][j]=b;
j=j+v;
b++;
r=b-2;
}
if(j>(n-1))
{
a[i][j]=r;
j=j+v;
r–;
}
}
k=k+2;
j=(2*n)-2;
r=c-2;
}
if(((i+j)==p+2)&&(i>=n))
{
f=1;
for(h=r;h>0;h–)
{
if(j<=(n-1))
{
a[i][j]=f;
j=j+v;
f++;
x=f-2;
}
if(j>(n-1))
{
a[i][j]=x;
j=j+v;
x–;
}
}
r=r-2;
p=p+2;
j=(2*n)-2;
}
}
}
for(i=0;i<=(2*n)-2;i++)
{
cout<<endl;
for(j=0;j<=(2*n)-2;j++)
{
if(a[i][j]!=0)
cout<<a[i][j];
else
cout<<” “;
}
}
break;
default:
cout<<“Wrong choice”<<endl;
break;

}
getch();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s