pascals triangle

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2004
Posts: 17
Reputation: let us c is an unknown quantity at this point 
Solved Threads: 1
let us c's Avatar
let us c let us c is offline Offline
Newbie Poster

pascals triangle

 
0
  #1
Aug 26th, 2004
hi
i want to display pascals triangle on computer screen.the pascals triangle
goes like this. and what is logic.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1 and so on.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 2
Reputation: ganesh is an unknown quantity at this point 
Solved Threads: 0
ganesh ganesh is offline Offline
Newbie Poster

Re: pascals triangle

 
0
  #2
Aug 28th, 2004
Hi there are many logics behind this problem. This is the simple logic. Though it is inefficient, this will give you a better approach to this program

a[0] = 1
for(i=0;i<n;i++){
for(j=0;j<=i;j++){
Value_to_print = a[j-1]+a[j];
/* Print the values in the order you want */
}
a[j] = 0
a[j-1] = Value_to_print
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 23
Reputation: iamboredguy is an unknown quantity at this point 
Solved Threads: 0
iamboredguy's Avatar
iamboredguy iamboredguy is offline Offline
Newbie Poster

Re: pascals triangle

 
0
  #3
Sep 2nd, 2004
Well, you can try this code, but I don't know if it will work beyond n=9.
  1. #include <iostream.h>
  2. #include <conio.h>
  3.  
  4. /* This program creates a half pyramid of nos. Created on 12.6.2k3. */
  5.  
  6. void main()
  7.  
  8. {
  9. int n, i, r;
  10. cout<<"Enter the number of numbers: ";
  11. cin>>n;
  12. if (n>9)
  13. cout<<"\n This won't work out. ";
  14. else
  15. {
  16. for (i=1; i<=n; i++)
  17. {
  18. for (r=1; r<=i; r++)
  19. {
  20. cout<<r;
  21. }
  22. cout<<endl;
  23. }
  24. }
  25. getch();
  26. }
  27.  
  28. /* Output:
  29. Enter the number of numbers: 7
  30. 1
  31. 12
  32. 123
  33. 1234
  34. 12345
  35. 123456
  36. 1234567
  37.  
  38. */
btw, I didn't know it was called a pascal's triangle. I used to refer to it just as a no. pyramid or whatever.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC