Need Help With Printing Pascal's Triangle In C

Closed Thread

Join Date: May 2005
Posts: 82
Reputation: indianscorpion2 is an unknown quantity at this point 
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

Need Help With Printing Pascal's Triangle In C

 
0
  #1
May 16th, 2005
hi my name is srikanth.i have been trying to develop a source code to print the pascal's triangle for the past three days.i have'nt had any success.i would be greatly obliged if anyone could give me a simple source code to print the pascal's triangle in C.
Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Need Help With Printing Pascal's Triangle In C

 
0
  #2
May 16th, 2005
If you've been working on it for 3 days, surely you have developed a starting point. Why don't you post your code, indicate specifically what's not working, and someone will help you.
Quick reply to this message  
Join Date: May 2005
Posts: 82
Reputation: indianscorpion2 is an unknown quantity at this point 
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

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

 
0
  #3
May 16th, 2005
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.
Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

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

 
0
  #4
May 16th, 2005
You didn't like the answer the first time so you post it again?
Quick reply to this message  
Join Date: May 2005
Posts: 82
Reputation: indianscorpion2 is an unknown quantity at this point 
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

i need an algorithm to print pascal's triangle

 
0
  #5
May 18th, 2005
i am a student of computer science.i require an algorithm to print the pascal's triangle.
Quick reply to this message  
Join Date: Apr 2004
Posts: 4,334
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 234
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need Help With Printing Pascal's Triangle In C

 
0
  #6
May 18th, 2005
Merged threads: indianscorpion2, please don't start new threads with the same topic in a relatively short period of time (a couple days). If you haven't had any success, how about starting with a failed attempt?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Need Help With Printing Pascal's Triangle In C

 
0
  #7
May 18th, 2005
Here's the mathematical way to do it. But if this is homework, your teacher is probably looking for the brute force way of doing it. I won't show you that one because half the fun is figuring things out for yourself. The other half is writing the code to do it.
  1. #include <iostream>
  2.  
  3. double factorial(double n)
  4. {
  5. return (n > 1) ? n * factorial(n - 1) : 1;
  6. }
  7.  
  8. double ncr(int n, int r)
  9. {
  10. return factorial(n) / (factorial(r) * factorial(n - r));
  11. }
  12.  
  13. int main()
  14. {
  15. std::cout.setf(std::ios::fixed, std::ios::floatfield);
  16. std::cout.precision(0);
  17.  
  18. for (int i = 0; i < 15; i++) {
  19. for (int j = 0; j <= i; j++)
  20. std::cout << std::right << ncr(i, j) << ' ';
  21. std::cout << std::endl;
  22. }
  23. }
Quick reply to this message  
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 >>
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,567
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 707
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Need Help With Printing Pascal's Triangle In C

 
0
  #9
Jul 28th, 2005
uzone24, one reason I haven't moderated your post is because the original question was posed several months ago. But we don't give answers to homework without effort on the student's part. The other reason is because your code both sucks and is horribly broken, so if someone bothered to turn it in, they would surely fail.
I'm here to prove you wrong.
Quick reply to this message  
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 Help With Printing Pascal's Triangle In C

 
0
  #10
Jul 29th, 2005
Originally Posted by Narue
uzone24, one reason I haven't moderated your post is because the original question was posed several months ago. But we don't give answers to homework without effort on the student's part. The other reason is because your code both sucks and is horribly broken, so if someone bothered to turn it in, they would surely fail.
Narue can u elaborate on reasons y my code sucks as well wud fail ??
Quick reply to this message  
Closed Thread

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC