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

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

 
0
  #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.
  1. #include<stdio.h>
  2. void main()
  3. {
  4. int ary[i][j],n;
  5.  
  6. printf("\nEnter the number of rows:");
  7. scanf("%d",&n);
  8.  
  9. for(i=0;i<n;i++)
  10. {
  11. for(j=0;j<=i;j++)
  12. {
  13. if(j==0!!j==1)
  14. ary[i][j]=1;
  15. else
  16. ary[i][j]=ary[i-1][j-1]+ary[i-1][j];
  17. }
  18. }
  19.  
  20. for(i=0;i<n;i++)
  21. {
  22. printf("\n");
  23. for(j=0;j<=i;j++)
  24. {
  25. printf("%d",ary[i][j]);
  26. }
  27. }
  28. }
<< moderator edit: added [code][/code] tags >>