Solved i want helop to product pascale traingle in unix

June 17, 2012 at 02:01:26
Specs: Windows 7
i want to help to product pascale traingle in unix

See More: i want helop to product pascale traingle in unix

Report •

#1
June 17, 2012 at 21:56:33
✔ Best Answer
Pascal Triangles are not my area of expertise. But I converted the "C" program at this link:

http://smartwebx.blogspot.com/2009/...

to an awk program:

# r is the number of rows of a pascal triangle
echo "5"|awk '
{
r=$0  # pass the number of rows, 5 in this case
for(i=0;i<r;i++)
   {
   for(s=1;s<=r-i;s++)
      printf(" ");
   for(n=0;n<=i;n++)
      printf(" %d",nCr(i,n));
   printf("\n");
   }
}

function fact(f)
{
   if(f==0)
      return 1;
   return f*fact(f-1);
}
function nCr(n, r)
{
return fact(n)/(fact(r)*fact(n-r));
} '


Report •
Related Solutions


Ask Question