RSS Forums RSS
Please support our C advertiser: Programming Forums

Need Help With Printing Pascal's Triangle In C

Join Date: Jul 2005
Posts: 3
Reputation: uzone24 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
uzone24 uzone24 is offline Offline
Newbie Poster

Re: need a source code in C to print pascal's triangle

  #8  
Jul 28th, 2005
Originally Posted by indianscorpion2
hi i am a student of computer science.i am a beginner.i am looking for a simple source code in C to print the pascal's triangle.the user should have the option to enter the number of rows he requires to view.i would be obliged if anyone could help out here.

#include<stdio.h>
void main()
{
int ary[i][j],n;

printf("\nEnter the number of rows:");
scanf("%d",&n);

 for(i=0;i<n;i++)
 {
  for(j=0;j<=i;j++)
  {
   if(j==0!!j==1)
   ary[i][j]=1;
   else
   ary[i][j]=ary[i-1][j-1]+ary[i-1][j];
  }
 }

 for(i=0;i<n;i++)
 {
  printf("\n"); 
  for(j=0;j<=i;j++)
  {
   printf("%d",ary[i][j]);
  }
 }
}
<< moderator edit: added [code][/code] tags >>
 
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:19 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC