//prg to display diamond and pascals triangle
//Downloaded From www.c4cpp.co.nr. (C)2009.All rights reserved.
#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();
}
Programs Can Also Be Downloaded From The Folders Below....[Or Scroll Down]
Pascals Triangle & Pattern
Click Here To Download C++ File Of This Program
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment