Subscribe Now: standard

Friday, October 23, 2009

How to - Pascals triangle using arrays - c++ code


Type: c++
hi all , here is the codes that print the pascals triangle using arrays  to generate it,
WARNING: IF YOU USE BORELAND TURBO C++ it may not allow to declare arrays using variables as size parameters in that case.
remove all lines marked with red and replace them with the text between  the \*  & */  near then. and declare a value for C = number of lines to be printed.

===================================================
#include
int main()
{
int ac,tc,d=0,k, bc,t,i=0,h,f;

int c;  \* int c= "your value" */
cout<<"Please enter the number of lines requeired";
cin>>c;
ac= (2*c)+1;
bc=2*c;
int a[ac];  \* int a[ value twise C  + 1]; */
tc=0;
a[bc]=0;
f=ac;
while(c>=tc)
{
cout<<" ";
tc++;
}
//=========================fill array
while(d<=ac)
{
if(d==c)
{
a[d]=1;
d++;
}

else
{
a[d]=0;
d++;
}
}

//===============================
cout<<"1 \n";;

k=c-1;
int y=0;
//================set and print nums
while(k>0)
{
//align==========
h=c-y;
while(h>0)
{
cout<<" ";
h= h-1;
}
y++;

//--------------------
d=0;
while(d
{
t=d+1;
a[d]=a[d]+a[t];
d++;
}
//==========print
i=0;
while(i
{
if(a[i]>0)
{
cout<<<" ";
i++;
}
else
{
i++;
}
}
cout<<"\n";
k--;
}

}


=================END=========================

for any further help you may please contact me at blaise.crowly@gmail.com

http://blaisemcrowly.co.cc

Blaise M Crowly

No comments:

Post a Comment