Tuesday, November 9, 2010

C Programs 01: Pascal's Triangle

#include<iostream.h>
main()
{
  int b,p,q,r,x;
  printf("enter number of rows : ");
  scanf("%d",&r);
  b=1;
  q=0;
  printf("\nPASCAL'S TRIANGLE\n");
  while(q<r)
  {
    for(p=30-3*q;p>0;p--)
    printf(" ");
    for(x=0;x<=q;x++)
    {
        if(x==0||q==0)
        b=1;
        else
        b=(b*(q-x+1)/x);
        printf("%6d",b);
    }
    printf("\n");
    q++;
   }
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes